Re: Try Finally...

From: Rob Kennedy (me3_at_privacy.net)
Date: 10/26/04


Date: Tue, 26 Oct 2004 12:26:31 -0500

L D Blake wrote:
> What should "Finally" do with continuable exceptions?

The same thing it already does: Ignore them.

> Ask why you need string info to handle an exception...

Not necessarily a string, but *some* additional information is
convenient to have. The exception I raise most often is EWin32Error. It
has a property, ErrorCode, which contains the value returned by
GetLastError. That function's range is already DWord, so it is not
feasible to just throw the error code as the exception code. EWin32Error
consolidates all the error codes into a single exception class.

EWin32Error also carries the string message of the error code. It's not
strictly necessary since any anything that catches the exception could
easily call SysErrorMessage on the error code, but then that's something
that would need to be duplicated in each exception handler, so it's more
effective to move that code into the code that creates the exception
instead, even if not *all* handlers require it.

Exceptions that I'm catching lately descend from EIBInterbaseError. It
has a numerical IBErrorCode property as returned by various Firebird API
functions. That error code might be isc_unique_key_violation, but that
number alone doesn't tell me *which* key has been violated. The
information I need is contained in the exception's Message property. I
parse the string, looking for the key name, and then I set focus to the
UI control that corresponds to the database field and ask the user to
enter a different value. I couldn't do that if the exception didn't tell
me which key was violated.

-- 
Rob


Relevant Pages

  • Re: Creating an error message table
    ... and the line number where the exception occurred. ... This is all well organized and well packed in a string object. ... all that s/he has to remember is the error code. ... > How about using an STL map as the data structure? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Structured exception information
    ... Doesn't feel as type-safe as advertised. ... What, _exactly_, will the handler do with the separate bits? ... Looking up the localized error message in the dictionary based on the *type-safe* error code that it got from the exception object, ... I'm looking forward to see a convincing solution for error code and the dictionary. ...
    (comp.lang.ada)
  • Re: Exception : an ugly grammer in programming
    ... machinism in programming languages. ... we return error code when we meet an error. ... But how about use exception in OOP? ... Exceptions originally were designed to handle unexpected conditions, ...
    (comp.lang.php)
  • Re: [PHP] Re: MySQL exceptions
    ... I don't think MySQL or even mysqli have any kind of exception throwing ... echo "Impossible connect to server."; ... completely before trying to use a dead connection. ... error code number would be encapsulated as an ...
    (php.general)
  • Exception : an ugly grammer in programming
    ... Yes, I'm doing PHP. ... machinism in programming languages. ... we return error code when we meet an error. ... But how about use exception in OOP? ...
    (comp.lang.php)