Home » SQL & PL/SQL » SQL & PL/SQL » Exception in Declare block
Exception in Declare block [message #8486] Mon, 25 August 2003 05:32 Go to next message
Reema
Messages: 50
Registered: July 2003
Member
Hi All,
I have a doubt regarding exception in Declare Block.If a exception is declared in Declare block then why it is not trapped in the Exception block.Whereas a exception raised in BEgin block is trapped.Following is the sample code I tried.
******************
DECLARE
a number NOT NULL:='qwe';
BEGIN
dbms_output.put_line ('YOUR IN BEGIN BLOCK');
a:= 'asf';

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('YOUR IN EXCEPTION BLOCK');
END;
Re: Exception in Declare block [message #8495 is a reply to message #8486] Mon, 25 August 2003 11:52 Go to previous messageGo to next message
Scott Mackey
Messages: 46
Registered: February 2003
Member
First, you are misusing quite a few terms, and yes, it makes a difference. You have not "declared" an exception in your sample code. You have written a line that will error when runs, i.e. a runtime error. Declaring an exception looks like this.

MY_EXCEPTION EXCETPION;

Also, there isn't really a "Declare block" and an "Exception block". An Exeption section is part of a Begin/Exception/End block. Exception section are designed specifically to handle errors within that block. Since the Declare section is not part of the block there is no reason the Exception section should handle it. If you want to know how to trap errors created in the Declare section, you can't. But there is no reason you should ever have a runtime error in a declaration section. If you have one, then you have coded poorly.
Re: Exception in Declare block [message #8508 is a reply to message #8486] Tue, 26 August 2003 23:56 Go to previous messageGo to next message
kiran
Messages: 503
Registered: July 2000
Senior Member
Oracle cann't trap this exception in this block/procedure since the error is in the declaration section.

There is a wrok around for this type of exception that is,
u can catch/trap this type of exceptions in the calling rotinue.
create or replace procedure calledproc as
a number NOT NULL:='qwe';
BEGIN
dbms_output.put_line ('YOUR IN BEGIN BLOCK');
a:= 'asf';

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('YOUR IN EXCEPTION BLOCK');
END;

Begin
calledproc;
WHEN OTHERS THEN
dbms_output.put_line('YOUR IN EXCEPTION BLOCK DUE TO ERROR IN THE CALLED ROTINUE');
END;

Hope u understand.
Re: Exception in Declare block [message #8509 is a reply to message #8486] Tue, 26 August 2003 23:57 Go to previous message
kiran
Messages: 503
Registered: July 2000
Senior Member
Oracle cann't trap this exception in this block/procedure since the error is in the declaration section.

There is a wrok around for this type of exception that is,
u can catch/trap this type of exceptions in the calling rotinue.
create or replace procedure calledproc as
a number NOT NULL:='qwe';
BEGIN
dbms_output.put_line ('YOUR IN BEGIN BLOCK');
a:= 'asf';

EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('YOUR IN EXCEPTION BLOCK');
END;

Begin
calledproc;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('YOUR IN EXCEPTION BLOCK DUE TO ERROR IN THE CALLED ROTINUE');
END;

Hope u understand.
Previous Topic: ORA-01034: ORACLE not available
Next Topic: Between operator
Goto Forum:
  


Current Time: Thu Apr 25 23:35:59 CDT 2024