>Hi All, > >I was curious to hear people's opinions on the >following issue: > >In a PL/SQL procedure I have multiple exception >handlers which share a >considerable amount of code. For example, they all >typically display a >message to the screen, shutdown a few open files, >perform a rollback and >raise the exception. They all vary, however, at >the begining. > >Is it preferable (or even allowed) to combine the >common exception handling >into a single exception? I imagine it's preferred >if only for the reason >of improving readability and reducing the chances >of slightly messing one >up. What is the best way to share exception code? > >Regards, > Mark. > >PS: Is the below code even valid or is another >approach required? > >BEGIN > <some code here - hopefully!> >EXCEPTION > WHEN exc_case1 THEN > <something specific> > RAISE exc_common; > > WHEN exc_case2 THEN > <something different> > RAISE exc_common; > > WHEN exc_common THEN > <common exception code> > > WHEN OTHERS THEN > <panic a little bit> >END; >
Mark, Generally speaking I believe that 'code factoring' is a good idea. Keep specific things to a minimum (eg assigning an error number and/or message). That said your example is wrong : in an exception handler, you cannot 'jump', by raising an exception, to a same-level code; the exception you rise goes up one level. I guess that a simple example will be clearer : If you have Exception when A then raise c; when B then raise c; when C then <action> If A occurs then <action> will not be performed, because exception C will be returned one level higher. The proper way to do it is begin ... begin ... exception when A then raise C; when B then raise C; when others then raise; -- make explicit what is -- implicit end; exception when C then <action> when others ten ... end; HTH, Stephane Faroult Oriole -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Stephane Faroult INET: [EMAIL PROTECTED] Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).