Subject | Re: how can i handle the exception 'object' in a general way |
---|---|
Author | flipmooooo |
Post date | 2005-02-09T10:20:16Z |
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
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
wrote:
> At 08:44 AM 9/02/2005 +0000, you wrote:exception occur
>
>
> >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
> in your code:typically,
>
> 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 -
> starting with the most specific and working down to the mostgeneric:
>at the
> 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
> current level, the engine will keep working its way outwards,through the
> BEGIN...END blocks in the main execution flow, until it finds asuitable
> handler. If it reaches the final END statement and it hasn't founda
> handler that fits the exception that was thrown, it returns controlto the
> client, returning that exception.errors (a
>
> Note, you can also have handlers listening for specific SQLCODE
> negative 3-digit number, e.g. -902) or gdscode errors (which aresymbols,
> like e.g. arith_except, which is the symbol for gdscode 335544321,with the
> message "Arithmetic exception, numeric overflow, or stringtruncation").
>handle. If
> You should only write handlers for things you actually want to
> you want to return the exception, let the engine take care of it.to a
>
> You might also want to use a handler to assign some specific text
> custom exception, before re-raising it. You can read about this inthe
> 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