Re: Array of Exceptions
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Mar 2007 20:19:31 -0400
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
.
- References:
- Array of Exceptions
- From: pascal
- Re: Array of Exceptions
- From: Daniel Pitts
- Re: Array of Exceptions
- From: pascal
- Re: Array of Exceptions
- From: Daniel Pitts
- Re: Array of Exceptions
- From: pascal
- Re: Array of Exceptions
- From: Tom Hawtin
- Re: Array of Exceptions
- From: pascal
- Array of Exceptions
- Prev by Date: Re: Read 7-zip archive with java
- Next by Date: Re: How to Get a Remote File HTML Code with Java?
- Previous by thread: Re: Array of Exceptions
- Next by thread: Re: Array of Exceptions
- Index(es):
Relevant Pages
|