Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: RAISED EXCEPTION not well caught

Re: RAISED EXCEPTION not well caught

From: tojo <Tojo_at_hotmail.com>
Date: Tue, 9 Mar 2004 09:12:51 +0100
Message-ID: <MPG.1ab79af2db56f009896df@news.t-online.de>


In article <c2ioft$1td48f$1_at_ID-117651.news.uni-berlin.de>, peterwu_at_hotmail.com says...
> On 08/03/2004 4:13 PM, Daniel Morgan wrote:
>
> > Peter Wu wrote:
> >
> >> Hello group,
> >>
> >> I'm new to Oracle PL/SQL.
> >>
> >> I have written a test script as follows.
> >>
> >> BEGIN
> >> select min(contract_start_date)
> >> into l_min_contract_start_date
> >> from contracts
> >> where customer_last_name = 'Bush';
> >>
> >> if (l_min_contract_start_date is null) then
> >> raise NO_DATA_FOUND;
> >> end if;
> >>
> >> BEGIN
> >>
> >> /* do something */
> >>
> >> EXCEPTION WHEN NO_DATA_FOUND THEN
> >> BEGIN
> >> /*
> >> do something to handle the exception within
> >> the nearest BEGIN
> >> */
> >>
> >> -- Exception Handler1
> >>
> >> END;
> >> END;
> >>
> >>
> >>
> >> EXCEPTION WHEN NO_DATA_FOUND THEN
> >> BEGIN
> >> /*
> >> do something to handle the excpetion raised by
> >> contract_start_date SELECT */
> >>
> >> -- Exception Handler2
> >>
> >> END;
> >> END;
> >> END;
> >>

It isn't very clear how your code is supposed to flow. I would just restructure like this:

     select min(contract_start_date)
     into l_min_contract_start_date
     from contracts
     where customer_last_name = 'Bush';

     if (l_min_contract_start_date is null) then

	 -- Run code from Exception Handler2

     else
        BEGIN

	     /* do something */

	 EXCEPTION WHEN NO_DATA_FOUND THEN
           -- Exception Handler1
 
        END;
     end if;	 

Doesn't make much sense to trap an error, re-raise the error, then retrap.

Received on Tue Mar 09 2004 - 02:12:51 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US