Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Array of Exceptions

Reply
Thread Tools

Array of Exceptions

 
 
Lew
Guest
Posts: n/a
 
      03-15-2007
pascal wrote:
> I got it to work...
> Thanks to all, you provide the key ideas to get this to work.
> You can cut and paste the following code into an IDE.
> Hit the go button and the exception thrown depends on the array index
> of the exception array.
> Change the call to the method from x to y to z to see the effect.
> I can now take these ideas and incorporate them into my program.


Bravo.

The approach I use is to declare one or two project-specific exceptions, one
checked and the other unchecked, e.g., FabulatorException and
FabulatorRuntimeException. Whenever the code catches a lower-level exception,
e.g., IOException, if I must rethrow it I rethrow the standard one with the
original one as the cause.

catch ( IOException ex )
{
String msg = "Some sensible log message with project-specific information. "
+ ex.getMessage();
logger.error( msg );
logger.debug( ex.getStackTrace() );
closeExternalResources();
throw new FabulatorException( msg, ex );
}

The times when I would rethrow a checked exception are few and far between in
any event.

catch ( IOException ex )
{
String msg = "Some sensible log message with project-specific information. "
+ ex.getMessage();
logger.error( msg );
logger.debug( ex.getStackTrace() );
closeExternalResources();
return ERROR;
}

The problems with the array approach are its verbosity and the reduction in
self-documentativity of the source. With only one custom Exception (or one
each of checked and unchecked), an array is completely superfluous anyhoo.

-- Lew
 
Reply With Quote
 
 
 
 
Daniel Pitts
Guest
Posts: n/a
 
      03-15-2007
On Mar 14, 9:52 am, "pascal" <(E-Mail Removed)> wrote:
> I got it to work...
> Thanks to all, you provide the key ideas to get this to work.
> You can cut and paste the following code into an IDE.
> Hit the go button and the exception thrown depends on the array index
> of the exception array.
> Change the call to the method from x to y to z to see the effect.
> I can now take these ideas and incorporate them into my program.
>

Oh, you weren't just asking a theory question?

I would then ask WHY you are doing this? The design looks error prone
and unmaintainable. What reasons do you have to use this
(anti-)pattern?

 
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
const and array of array (of array ...) Mara Guida C Programming 3 09-03-2009 07:54 AM
Exceptions - How do you make it work like built-in exceptions? Lie Python 3 01-14-2008 06:45 PM
Exceptions + Performance on path without exceptions gratch06@gmail.com C++ 3 04-16-2007 08:52 PM
Checked exceptions vs unchecked exceptions Ahmed Moustafa Java 5 07-14-2004 01:46 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM



Advertisments