Subject Re: how can i handle the exception 'object' in a general way
Author flipmooooo
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
> At 08:44 AM 9/02/2005 +0000, you wrote:
>
>
> >Hi,
> >
> >I created some custom exceptions, how can i handle the
> >exception 'object' in a general way in the 'when exception block'?
> >
> >WHEN EXCEPTION Custom_Exception1, EXCEPTION Custom_Exception2 DO
> > BEGIN
> > MyException = EXCEPTION.RDB$EXCEPTION_NAME;
> > MyExceptionText = EXCEPTION.RDB$MESSAGE;
> > END
>
> You should probably get hold of the IB6 DataDef.pdf and look at the
> examples there.
>
> In order to cause a custom exception, you have to make that
exception occur
> in your code:
>
> BEGIN
> ...
> BEGIN
> ..........
> If (<something_you_dislke>) then
> exception Custom_Exception1;
> if (<something_else_horrible>) then
> exception Custom_Exception2;
> .........
> END
>
> Then handle exceptions in the order you want them handled -
typically,
> starting with the most specific and working down to the most
generic:
>
> WHEN Custom_Exception1 do
> BEGIN
> <do something to handle the exception>
> END
> WHEN Custom_Exception2 do
> BEGIN
> <do something to handle thIs exception>
> END
> WHEN ANY do
> BEGIN
> <do something to handle any other exception>
> END
> /* --------------------- */
> /* Now carry on */
> END
>
> You can nest exception blocks outwards - if a handler isn't found
at the
> current level, the engine will keep working its way outwards,
through the
> BEGIN...END blocks in the main execution flow, until it finds a
suitable
> handler. If it reaches the final END statement and it hasn't found
a
> handler that fits the exception that was thrown, it returns control
to the
> client, returning that exception.
>
> Note, you can also have handlers listening for specific SQLCODE
errors (a
> negative 3-digit number, e.g. -902) or gdscode errors (which are
symbols,
> like e.g. arith_except, which is the symbol for gdscode 335544321,
with the
> message "Arithmetic exception, numeric overflow, or string
truncation").
>
> You should only write handlers for things you actually want to
handle. If
> you want to return the exception, let the engine take care of it.
>
> You might also want to use a handler to assign some specific text
to a
> custom exception, before re-raising it. You can read about this in
the
> Firebird 1.5 release notes...
>

Hi,

Yes, i know i need some guide. Ordered 'The Firebird Book' on
www.ibphoenix.com but got an Email from them back that they were on
holliday, so i'll have to wait a bit. What i'm trying to get is
something like this. Hope its a bit more clear now. Anyway thanks for
all the help your guys are giving me.

Greetings,
Filip Moons

BEGIN
..........
If (<something_you_dislke>) then
exception Custom_Exception1 'Don't like that';
If (<something_you_dislke>) then
exception Custom_Exception1 'Don't like that either';
if (<something_else_horrible>) then
exception Custom_Exception2 'Sounds horrible';
.........
END


DECLARE VARIABLE MyException VARCHAR(31);
DECLARE VARIABLE MyExceptionText VARCHAR(78);


WHEN EXCEPTION Custom_Exception1, EXCEPTION Custom_Exception2 DO
BEGIN
/* 'Custom_Exception1' or 'Custom_Exception2' */
MyException = EXCEPTION.RDB$EXCEPTION_NAME;
/* 'Don't like that' or 'Don't like that either' or 'Sounds
horrible' */
MyExceptionText = EXCEPTION.RDB$MESSAGE;
INSERT INTO TMPLOG
(...,TMPLOEXCEPTION_NAME,TMPLOEXCEPTION_MSG,...)
VALUES
(...,:MyException,:MyExceptionText,...);
END


> ./heLen