Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Java Exception Safety

Reply
Thread Tools

Re: Java Exception Safety

 
 
Stefan Ram
Guest
Posts: n/a
 
      06-25-2009
"Scott A. Hightower" <> writes:
>I seem to remember running across a reference to a discussion,
>consensus or policy regarding the guarantees of exception
>safety appropriate to Java. But I didn't capture it at the time
>and now have no idea where to look. Any pointers?


For every exception-safe method:

First, use operations that can throw to try to obtain
results, storing them in temporary variables

Make sure that all resources allocated in the preceding
step get released iff this block was left due to a
run-time error

(This might not be needed in C++, when it happens
automatically by RAII, in Java, something like this can be
done using »finally«.)

Otherwise, now assign the temporary results to the actual
result(s) of the function, using only operations that can
not throw

In other words: Every method has to be a transaction:
Either it succeeds and all resources are allocated
successfully, or it fails and no resource is allocated.
(To some extend, this also should be valid for
certain side-effects to the environment.)

For some reason, this topic seems to be omitted in the
Java culture. So, I have written my own ideas, above,
actually, ideas taken from the C++ community.

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      06-26-2009
Stefan Ram wrote:
> (C) Copyright 2009 Stefan Ram. All rights reserved.
> Distribution through any means other than regular
> usenet channels is forbidden. It is forbidden to
> publish this article in the world wide web. It is
> forbidden to change URIs of this article into links.


<http://groups.google.com/group/comp.lang.java.programmer/msg/a99c5e17830ed474>

> It is forbidden to remove this notice or to transfer
> the body without this notice.


Is it permitted to transfer the notice without the body?

To follow up on what Peter said, how are we supposed to honor even such an
unenforceable copyright notice if we can't even read it without viewing the
headers, which I, at least, almost never do?

--
Lew
 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      06-26-2009
Scott A. Hightower wrote:
[ SNIP ]

> Sorry, I guess I wasn't concise.
>
> If someone is aware of a continuing discussion forum, a consensus or policy
> that addresses exception safety in Java, please post a pointer to it. Of
> particular interest are defined levels of guarantees appropriate to Java.
> What I seem to remember (and the memory is vague) was approximations to
> Basic, Strong and No Throw that accounted for asynchronous exceptions.
>
> But thanks for the quick response, anyway!
>
>

http://www.octopull.demon.co.uk/java...ionalJava.html

AHS
 
Reply With Quote
 
Arved Sandstrom
Guest
Posts: n/a
 
      06-26-2009
Scott A. Hightower wrote:
[ SNIP ]

> So, it took seven or eight years for the C++ community to reach a consensus.
> Exceptions were present when Java was introduced to the world, so we've had
> thirteen years. Are we close to "official" consensus? Is there even an
> ongoing "official" discussion?


I'm not aware of any ongoing "official" discussion. That doesn't mean
there isn't one.

Exception safety in the sense described in the article is a very valid
concern. I'm not aware of any way of coding methods to the basic and
strong exception guarantees (as described) other than the developer
being aware of state changes through the course of the method, knowing
where exceptions could be thrown in the method, and writing code to
handle those eventualities (ultimately ensuring that system state is not
unusable, or hasn't changed).

The author asserts (in 2002) that the Java community at large doesn't
keep these (by any name) exception safety benchmarks in mind when coding
methods. That's probably true for the majority of Java programmers.
However, I'd wager that good Java programmers do code to these
guidelines even if they're not aware of names for them.

AHs
 
Reply With Quote
 
Seamus MacRae
Guest
Posts: n/a
 
      06-26-2009
Lew wrote:
> Stefan Ram wrote:
>> (C) Copyright 2009 Stefan Ram. All rights reserved.
>> Distribution through any means other than regular
>> usenet channels is forbidden. It is forbidden to
>> publish this article in the world wide web. It is
>> forbidden to change URIs of this article into links.

>
> <http://groups.google.com/group/comp.lang.java.programmer/msg/a99c5e17830ed474>
>
>
>> It is forbidden to remove this notice or to transfer
>> the body without this notice.

>
> Is it permitted to transfer the notice without the body?
>
> To follow up on what Peter said, how are we supposed to honor even such
> an unenforceable copyright notice if we can't even read it without
> viewing the headers, which I, at least, almost never do?


It's not so much unenforceable as simply superfluous, like any copyright
statement that forbids a whole bunch of things but doesn't grant
permission for anything. Since the default copyright on everything is
"all rights reserved" anyway, anything a copyright notice explicitly
forbids either was forbidden anyway, without needing an explicit
forbidding, or else is allowed anyway, because it's fair use.

Of course, we in the software world should be used to seeing such
superfluous copyright notices. Nearly every piece of software comes with
a ridiculously long and hard-to-read one. The refreshing exceptions are
the open source programs that come with notices explicitly granting
permission to do things normally reserved, such as distribute copies,
under some conditions, such as that you distribute the source.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
Combining Java Reflection API with Java Annotation Types for Thread Safety pek Java 2 10-23-2007 03:00 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
array exception safety Klaus Ahrens C++ 1 12-08-2003 03:50 PM
Exception safety in the STL John Harrison C++ 5 07-08-2003 05:55 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57