Re: Array of Exceptions



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
.



Relevant Pages

  • Re: regex question - trying to find ".mp3" in a SELECT box
    ... But `Array' is a Function object reference. ... Establish a new execution context using F's FormalParameterList, ... Since is not a primitive value, the exception should be thrown. ... | 5.2 Algorithm Conventions ...
    (comp.lang.javascript)
  • Re: An isArray test (and IE bugs)
    ... is not 'Array' must not be an Array, ... You have no choice but to catch every exception that is thrown in a - try - block, but only the exceptions that you expected to be catching should be handled in the - catch - block. ... That suggests that each - catch - block should contain the code to identify the exact type and nature of the exception thrown so that all the exceptions that you did not expect to be catching can be re-thrown. ... So while you could examine the strings in an given set of browsers/browser configurations you are going to hard pressed to be in a position to identify the exception in a browser that you have never seen. ...
    (comp.lang.javascript)
  • Re: Assigning generator expressions to ctype arrays
    ... That's because I don't think it needs a temporary array. ... Since slice assignment does not use temporary arrays ... exception if the iterator wasn't exhausted. ...
    (comp.lang.python)
  • Re: Representing Dynamic Arrays in VB.NET
    ... At first I thought to use a three-dimensional array, but that quickly fell apart. ... public xRec as string =vbnullstring ' define dynamic array somewhere ... catch ex as exception ... set (byval value as string) ...
    (comp.databases.pick)
  • How do you store a stoopid array in the stoopid ViewState?
    ... Object reference not set to an instance of an object. ... An unhandled exception occurred during the execution of the ... Is there any way to create an immediate array in C#? ... public void Page_Init (object sender, ...
    (microsoft.public.dotnet.languages.csharp)