Use of raise in exception handling block
what is the use of raise in exception handling block for eg.
declare
a number;
b emp.empno%type;
begin
begin
SELECT empno INTO a FROM emp where 1=2;
exception
when others then
dbms_output.put_line('inner');
raise;
end;
exception
when no_data_found then
dbms_output.put_line('outer');
end;
output will be like below ..
inner
outer
PL/SQL procedure successfully completed.
my question is wht is the use of using raise in exception handing part, is there any specific reason we use in the development ????
Regards,
AAK.
In the first block, you do not raise you user-defined exception WHEN_NO_DATA_FOUND, but the predefined one, which is raised to the WHEN OTHERS exception handler.
Consider:
SQL> declare
2 a number;
3 my_err exception;
4 no_data_found exception;
5 begin
6 begin
7 select 1 into a from dual where 1=2;
8 exception
9 when no_data_found then
10 dbms_output.put_line(' In system defined');
11 raise my_err;
12 end;
13 exception
14 when my_err then
15 dbms_output.put_line('In User Defined');
16 when others then
17 declare
18 v_sqlerrm varchar2(100);
19 begin
20 v_sqlerrm := sqlerrm;
21 dbms_output.put_line(' In when others '||sqlerrm);
22 end;
23 end;
24 /
In when others ORA-01403: no data found
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 declare
2 a number;
3 my_err exception;
4 --no_data_found exception;
5 begin
6 begin
7 select 1 into a from dual where 1=2;
8 exception
9 when no_data_found then
10 dbms_output.put_line(' In system defined');
11 raise my_err;
12 end;
13 exception
14 when my_err then
15 dbms_output.put_line('In User Defined');
16 when others then
17 declare
18 v_sqlerrm varchar2(100);
19 begin
20 v_sqlerrm := sqlerrm;
21 dbms_output.put_line(' In when others '||sqlerrm);
22 end;
23* end;
SQL> /
In system defined
In User Defined
PL/SQL procedure successfully completed.
SQL>Note that in the second block, I deleted the declaration of the user defined exception NO_DATA_FOUND.
This is taken from the documentation:
Redeclaring Predefined Exceptions
Remember, PL/SQL declares predefined exceptions globally in package STANDARD, so you need not declare them yourself. Redeclaring predefined exceptions is error prone because your local declaration overrides the global declaration. For example, if you declare an exception named invalid_number and then PL/SQL raises the predefined exception INVALID_NUMBER internally, a handler written for INVALID_NUMBER will not catch the internal exception. In such cases, you must use dot notation to specify the predefined exception, as follows:
EXCEPTION
WHEN invalid_number OR STANDARD.INVALID_NUMBER THEN
-- handle the error
END;You can read yourself :
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/errors.htm
Regards,
Gerd
Similar Messages
-
What is the Use of throws in Exception Handling
I have clear idea about try,catch,finally, but i do not have clear idea about throws
Can u anyone explain about throws with example program?
Thanks>
I have clear idea about try,catch,finally, but i do not have clear idea about throws
Can u anyone explain about throws with example program?
>
Yes - the Java Tutorial can explain it and has examples
http://docs.oracle.com/javase/tutorial/essential/exceptions/
And all of the Java Language constructs, including 'throws' are defined in the Java Language Specification
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.6
>
8.4.6. Method Throws
A throws clause is used to declare any checked exception classes (§11.1.1) that the statements in a method or constructor body can throw (§11.2.2). -
Exception Handling - WHEN OTHERS
Good Day to All,
When i am running a procedure in TOAD-Expert... it says below message.
*'Avoid using a WHEN OTHERS clause in an exception section without any other specific handlers.'*
PROCEDURE...
IS
BEGIN
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
-- Checking whether cursor is open
IF cur%ISOPEN THEN
CLOSE cur;
END IF;
UPDATE TABLE
SET COL..
WHERE ...
COMMIT;
RAISE;
END procedure;The manner in which you are dealing with the exception is not wrong. Your handler does a couple of things:
- rollbacks the existing transaction as failed
- attempts resource protection (guard against resource leakage)
- logs the error
- re-raises the exception
None of these are invalid actions when dealing with an exception.
A suggestion though - move the UPDATE out of the exception and create a procedure that performs the logging for you (as an autonomous transaction). This way you have a reusable logging code unit that can be called from anywhere in your code.
Resource protection for explicit cursors are also not that critical in PL/SQL - as cursor handles that go out of scope are automatically released. The exception being a ref cursor handle. Of course, you need to resource protect other handles (like socket and file handles). And seeing that PL/SQL does not offer resource protection blocks, the only alternative is to use the "+when OTHERS+" exception handler for that. -
UTL file exception handling oracle 11g
We use oracle 11g
We use UTL file and exception handling in many place. Thanks in advance.
We have many utl program and we are writing same exception handling code ,copy and paste .
It is possible to create new UTL exception procedure and call it.
I am not sure how to write generic UTL exception procedure and reuse the same.
I am learning oracle etl files method.
Please advise.
sample program 1 :
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('test_dir', 'test_file.txt', 'W');
UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
when utl_file.invalid_path then
raise_application_error(-20001,
'INVALID_PATH: File location or filename was invalid.');
when utl_file.invalid_mode then
raise_application_error(-20002,
'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
when utl_file.invalid_filehandle then
raise_application_error(-20002,
'INVALID_FILEHANDLE: The file handle was invalid.');
when utl_file.invalid_operation then
raise_application_error(-20003,
'INVALID_OPERATION: The file could not be opened or operated on as requested.');
when utl_file.read_error then
raise_application_error(-20004,
'READ_ERROR: An operating system error occurred during the read operation.');
when utl_file.write_error then
raise_application_error(-20005,
'WRITE_ERROR: An operating system error occurred during the write operation.');
when utl_file.internal_error then
raise_application_error(-20006,
'INTERNAL_ERROR: An unspecified error in PL/SQL.');
when utl_file.invalid_filename then
raise_application_error(-20010, 'The filename parameter is invalid.');
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(fileHandler ) THEN
UTL_FILE.FCLOSE (fileHandler );
END IF;
RAISE;
END;
How to write generic procedure of utl exception handling ?
please advise.
create or replace procedure sp_utl_exception
begin
when utl_file.invalid_path then
raise_application_error(-20001,
'INVALID_PATH: File location or filename was invalid.');
when utl_file.invalid_mode then
raise_application_error(-20002,
'INVALID_MODE: The open_mode parameter in FOPEN was invalid.');
when utl_file.invalid_filehandle then
raise_application_error(-20002,
'INVALID_FILEHANDLE: The file handle was invalid.');
when utl_file.invalid_operation then
raise_application_error(-20003,
'INVALID_OPERATION: The file could not be opened or operated on as requested.');
when utl_file.read_error then
raise_application_error(-20004,
'READ_ERROR: An operating system error occurred during the read operation.');
when utl_file.write_error then
raise_application_error(-20005,
'WRITE_ERROR: An operating system error occurred during the write operation.');
when utl_file.internal_error then
raise_application_error(-20006,
'INTERNAL_ERROR: An unspecified error in PL/SQL.');
when utl_file.invalid_filename then
raise_application_error(-20010, 'The filename parameter is invalid.');
WHEN OTHERS THEN
IF UTL_FILE.IS_OPEN(fileHandler ) THEN
UTL_FILE.FCLOSE (fileHandler );
END IF;
RAISE;
end;Mahesh Kaila wrote:
Hello,
Common procedure to log exception in log file
create or replace procedure sp_utl_exception (log_dir varchar2, log_file varchar2, exception_msg varchar2)
is
hnd_file UTL_FILE.file_type;
begin
hnd_file := UTL_FILE.fopen (log_dir, log_file, 'A');
UTL_FILE.put_line (hnd_file, exception_msg);
UTL_FILE.fclose (hnd_file);
exception
when others
then
raise;
end;
Very poor implementation.
a) Absolutely no need for that exception handler in there. It should be removed.
b) As it's a procedure for logging exceptions relating to UTL_FILE, it would seem error prone to be logging the errors with UTL_FILE. For example, what is it supposed to do if the exception is raised because of lack of disk space in those file locations? How is it going to write out the exception with the disk full? Also, if the exception handler is used by multiple processes, then only 1 process at a time can access the log file to write it's exceptions, so it doesn't scale well. Better logging is done by having an autonomous transaction procedure that writes log/trace messages to dedicated table(s). That also means that the logs etc. can be viewed, as appropriate, from any client using SQL (either manually or through a application written to view logs etc.), rather than requiring physical/remote access to the server o/s to go and view the contents of the file, which in itself could lock the file and prevent any process from writing further logs whilst it's being used. -
Why to raise an exception?
Hello
I am trying to understand that why do we RAISE an Exception.
I was seeing some documentation. where it gave this example
(to check if any rows were updated or not, it uses SQL%NOTFOUND)
DECLARE
BEGIN
UPDATE Tablename
IF SQL%NOTFOUND
RAISE e_invalid_Item
END IF
COMMIT;
EXCEPTION
WHEN e_invalid_Item
DBMS_OUTPUT.PUT_LINE ('No such Item);
END;
I was thinking
why cant we simply use the if statement to display. like below
IF SQL%NOTFOUND
DBMS_OUTPUT.PUT_LINE('.................');
END IF
So why to raise an exception and then display DBMS_OUTPUT........
Why dont we just display it where it happened?
What is really and USE of raising an exception?
thank youI am trying to understand that why do we RAISE an Exception."An exception is a runtime error or warning condition, which can be predefined or user-defined. Predefined exceptions are raised implicitly (automatically) by the runtime system. *User-defined exceptions must be raised explicitly by RAISE statements*. To handle raised exceptions, you write separate routines called exception handlers."
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/exception_definition.htm#LNPLS01316
http://www.oracle.com/pls/db102/homepage
http://www.oracle.com/pls/db112/homepage
You only catch exceptions when you expect them, and then deal with them, let them propagate to the caller.
Hopefully this (imo) classic 'rant' will make you understand better:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1509245700346768268#tom1535781400346575552
Never ever swallow an exception by catching one and just 'dbms_output.put_line' it. Doing so, is the same as making success out of failure. Please read the link. It should give you ideas on how things (should) work.
Only catch exceptions you expect. -
BPM Process - Exception handling or timeout issues?
Hi Guys,
I have a BPM process as below.
1. Receive step: Receive the file with multiple transactions.
2. Transformation step: Split the file into individual transactions
3 Block step which includes -- par for each mode
1. Send Step (Synchronus): Each individual transaction needs to contact the 3rd party system and get the response. -- Do i need to handle any exceptions here ?
2. Container : Collect all the responses
Block ends
4. Transformation: combine all the responses in to a single file
5. Send Step: synchronus -- send the above single file and get the response back
6. Transformation : Transform the above response into the target structure.
7. Send: send the message asynchronusly to the target system
I need suggestion regarding the exceptional handling or any time out issues, i need to take care of.
any suggestions would be really appreciated
Thanks,
Raj
Edited by: raj reddy on Feb 12, 2009 10:12 PMHi,
I) For the Block holding the Sync Send, create an Exception Block. (right click on Sync Send -> Insert -> Exception Branch)
II) Name the Exception block (ex: exceptionHandler).
III) in the Sync Send step ->Properties -> Exceptions -> in System Error - add exceptionHandler.
IV) Now within the Exception handler block you can create containers to hold values from payload, throw exception as email etc).
This will cover your sync send step incase there is an error while sending the request of a timeout during receiving the response.
You can also do the same for the Step 7) Asycn send - if required.
Another suggestion in your question Step 6) can be done outside the bpm, when you do the interface determination for that Asycn Send you can add the Interface mapping that will map the responses to the target structure.
Doing this will reduce one step in your BPM. For further information in how more you can fine tune your bpm, read this blog - https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/5113. [original link is broken] [original link is broken] [original link is broken]
All the best.
Regards,
Balaji.M -
An exception handler is obligatory for synchronous RFC communication
I am getting the error "An exception handler is obligatory for synchronous RFC communication" when I try to activate an Integration Process. Under a synchronous Send step, under Exceptions, I have System Error and the RFC.Exception Application Error to be handled. For both I have given the same Exception handler block. Is this not allowed? Why am I not able to go to same Exception handler block in case of both System Error as well as Application Error?
Thanksyou are right, it was erroring out due to the next step. Now if there is system error or exception, it will go to the exception branch. Here I need to have the ability to restart the process from this point after being alerted and having fixed the issue. So I am thinking of doing the send step again in the exception branch. But since the application error initially will exist soon after the alert is issued, this step will complete as I cannot handle application error a second time (this is where it was giving that error that exception handler was mandatory).
Is there a way in which I can stop/fail the process after the exception branch gives the alert so that I can restart the failed branch again? -
Problems with Custom Exception Handler
Hi,
I have defined a custom exception handler for my workflow (WebLogic Platform
7).
I have a workflow variable called 'count' , which gets incremented for every
time an exception occurs.
The exception handler checks if the count is less than 3(using evaluate
condition),
if yes then it executes the action "Exit Execption Handler and retry"
else
it executes the action "Exit Execption Handler and continue"
The Workflow simply hangs, nothing on the console , the worklist from which
i call it hangs too.
Has anyone managed to use this kind of exception handling?
Thanks in advance,
Asifbill0 wrote:
> Thanks for all the help but still no luck.
>
> The directory is d:\wSites\GBMain\html\CFMS> and I am
mapped to it as x:\CFMS.
> Most of the cfm files are in CFMS but Application.cfm is
1 directory up in
> html. I have tried misscfm.cfm in both html and CFMS but
had no luck having it
> find a non existant template referred to in a cfinclude
or a form's action
> attribute. The default ColdFusion error handler is what
shows. The missing
> template handler box says /misscfm.cfm. Misscfm.cfm is
text followed by a
> <cfabort>. We use ColdFusion MX6.1
>
> I hope that is enough information to figure what am I
missing and/or doing
> wrong.
>
>
Is the 'misscfm.cfm' file somewhere in the
'd:\wSites\GBMain\html\CFMS\'
directory. I will presume this is the 'web root' as defined
in your web
server (IIS or Apache or built-in or ???). The missing
template handler
file needs to be in the ColdFusion root. This is going to be
a
directory such as
'{drive}:\JRun4\servers\{server}\cfusion-ear\cfusion-war\misscfm.cfm'
for J2EE flavors OR '{drive}:\CFusionMX\wwwroot' for Standard
I think.
It has been a very long time since I have dealt with
Standard.
This is probably completely different from the above web
root. That is
the point I am trying to get across. ColdFusion has TWO roots
where it
will look for a CFML file. But the Missing and Sitewide
templates can
only be in the ColdFusion root listed above, they will not
work in the
web root.
HTH
Ian -
Exception Handling In BPEL By using Catch Blocks or Fault Policies Or Both
I have a confusion regarding
Exception handling :
When Should i go for 1)Catch Block (Remote , or binding ) in bpel for exception handling .
2)Fault Policy , Fault binding.xml
Currently iam using catch blocks , but even fault policy is good , but can i use both...
Currently in My bpel ,when any error occurs i have to send a error notification by Email .
Currently i have exposed the email service which shuts emails and write a file with errored Message.
Hence if any error i will catch i in a parent BPEL, i will just invoke the above email, service .
So anybody can help me by giving the suggestion how to go for the best approach
Edited by: anantwag on Mar 23, 2011 6:31 AMCurrently in My bpel ,when any error occurs i have to send a error notification by Email .
Currently i have exposed the email service which shuts emails and write a file with errored Message.Seeing your use case I will suggest you to use fault handling framework (fault policy). Fault handling framework should be used where you need generic error handling framework which handles all the faults occured in any composite component. Generally BPEL catch block should be used to propagate error info/fault back to the client/to fault handling framework or to consume an error
Regards,
Anuj -
Exception Handling (in Mapping) with out using BPM
Hello All,
We are on SP17. I have a simple flow involving XI
JMS -> XI (Message Mapping -> XSL Mapping) -> Mail
I would like to send an email if there is an exception in any of the mapping. But I <b>don't want to use a BPM</b> for this exception handling. How can I do it?
Thanks
AbinashHi Abinash,
yes you can! See these..
/people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping
/people/sap.user72/blog/2005/02/23/raising-exceptions-in-sap-xi-mapping
All the best!
cheers,
Prashanth
P.S Please mark helpful answers -
System instability using reports that raise an exceptions
I am having a problem with some reports when I use the type "PL/SQL function body returning SQL query".
If the Function raise an exception, the apex's engine will call again the function and it raise again the exception. These will make a loop that doesn't end until you close the session. The problem is that this page consume all the recourse of the CPU and/or fill the partition where the logs are saved. All these generate Instability on the server and also could bring down the server.
To reproduce this error you have to follow this steps:
1) First create a simple function to return a raise.
FUNCTION DORTEGA_TEST_RAISE RETURN VARCHAR2 IS
BEGIN
DECLARE
A NUMBER;
BEGIN
A := 12/0; --This operation generate an exception.
END;
RETURN 'SELECT 1 FROM DUAL';
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
2) Create a empty page with one report region.
3) Edit the report region and set these values:
a. Type = SQL Query (PL/SQL function body returning SQL query)
b. Display Point = Page Template Region Position 2
c. Source = BEGIN RETURN DORTEGA_TEST_RAISE; END;
Use Generic Column Names (parse query at runtime only)
4) When we run the application the page never load, and if you look the data base, you can view that the session it’s growing and it’s begins to consume all the memory and the processor of the server.
I am using APEX 3.1.0.00.32. And the DB is 11g.
Someone know why is this happening? Are there any fix for this bug?Hi:
I was able to reproduce this in APEX 3.1.2 installed in an Oracle XE instance.
The APEX engine does seem to go into an endless loop and the server Oracle process handling this request eventually does with an out-of-memory error.
However, if instead of raising an exception in the exception handler of the function I have a statement like 'Return Null;' then the APEX engine comes back with an expected response of
failed to parse SQL query:
ORA-00900: invalid SQL statement
Varad -
Avoid transaction roll back using exception handler
Hi everybody!
I've created a proxy service in OSB using a DB adapter for polling from a database table. I've configured the service to be transactional with same transaction for reponse. The proxy has a route node that routes to a business service created from a db adapter for storing the polled data. Insert table has a db trigger associated wich raises a custom exception in certain cases. I need to catch that exception in the route exception handler to avoid the full transaction to be marked rolled back. For this, I've setup a response with failure action in the handler.
After testing the service I realized that it's not working as expected as transaction is being rolled back when the trigger raises the exception (so registry is not marked as polled in source table).
Could anyone explain me which action should be taken to avoid a rollback when handling exception?
Best regards,
Daniel.Hi Athhek,
If I set reply with success then both route node and system error handlers are executed. I get following response metadata
<con:metadata xmlns:con="http://www.bea.com/wli/sb/test/config">
<tran:response-code xmlns:tran="http://www.bea.com/wli/sb/transports">1</tran:response-code>
</con:metadata>
and also following error reaches system handler:
<con:fault xmlns:con="http://www.bea.com/wli/sb/context">
<con:errorCode>BEA-382050</con:errorCode>
<con:reason>
Expected active transaction, actual transaction status: Marked Rollback
</con:reason>
<con:location>
<con:path>response-pipeline</con:path>
</con:location>
</con:fault>
When I set reply with error only route node handler is executed but I still get
<con:metadata xmlns:con="http://www.bea.com/wli/sb/test/config">
<tran:response-code xmlns:tran="http://www.bea.com/wli/sb/transports">1</tran:response-code>
</con:metadata>
Thank you. -
Implementing Exception Handling Application Block in custom web parts, event receivers
hi,
I am currently implementing try {} catch(Exception expp) { throw expp;} to handle exceptions in my intranet appln.
I have several custom web parts, event receivers, few console applciations as timer jobs etc. If i want to implement a robust exception handling what should be the approach. by searching, i saw, ms patterns n practices provides the
appln blocks.
But I think[ pls correct me if i am wrong ] those appln blocks are meant for asp.net applns ONLY.
if not, anyone has implemented those appln blocks in SP development? if yes, can anyone provide one sample / link to implement Exception Handling in SP.
help is appreciated!Hi,
Here are some articles for your reference:
Handling Error Centrally in a SharePoint Application
http://www.codeproject.com/Articles/26236/Handling-Error-Centrally-in-a-SharePoint-Applicati
Using Microsoft Enterprise Library Application Block in SharePoint
http://www.codeproject.com/Articles/21389/Using-Microsoft-Enterprise-Library-Application-Blo
Exception Handling in SharePoint
http://spmatt.wordpress.com/2012/02/01/exception-handling-in-sharepoint/
Best Regards
Dennis Guo
TechNet Community Support -
May I use Exception Handling for validation ?
Hello All,
Can any one know about that may i use exception handling for validation in my report program.
Please if its possible then give me some Example...
Thanks.Hi Niraj,
Exception is not at all raised or handled in the given example.
There are so many document available in the SCN regarding OO ABAP you can read that.
As far as validation of a field ( Selection screen ) of course we can do that but I don't see any advantage more over it will make your code unnecessarily complex.
Regards
Bikas -
FRM-40735: WHEN-NEW-BLOCK-INSTANCE trigger raised unhandled exception ORA-0
I have created two control blocks.In the second control block an item is getting data depending on the value of a particular item in the 1st control block.
I am fetching data for the item in 2nd block using WHEN-NEW-BLOCK-INSTANCE trigger in the 2nd block
It is giving the following error
FRM-40735: WHEN-NEW-BLOCK-INSTANCE trigger raised unhandled exception ORA-01403
When I am giving the following code, it is working
SELECT BM_MR_LCL_STD INTO :BLOCK2.ITEM5 FROM FABRIC_TYPE_MAST_DVLP WHERE FABRIC_TYPE = 'AT';
But when I am giving the below code, it is not working,
SELECT BM_MR_LCL_STD INTO :BLOCK2.ITEM5 FROM FABRIC_TYPE_MAST_DVLP WHERE FABRIC_TYPE = :BLOCK1.ITEM4;
Please Help.
Regards,That means there were no rows in the table which matched the criteria in your query. You need to trap the no_data_found exception, eg
exception
when no_data_found then
:block2.item5 := null;
end;and if fabric_type is not unique then you'll need to trap the too_many_rows exception too.
I think for this you might be better off with an explicit cursor.
Maybe you are looking for
-
Sales order change BAPI not updating items Profit center
Dear , I am facing the problem in using the BAPI for Item 's profit centre in blank space. I write down the below code <but it's not at all updating the profite centre . please ccorrect the code if any required' TYPES: BEGIN OF file_data , vb
-
Newly bought imac 27 desktop not responding, cursor moves only.
My setup did not go well as I was stuck in VoiceOver mode. Command f5 got me out of it but cannot do anything on the desktop, track pad moves cursor but by taping on it the icons do not respond. I am new to apple products, used to windows 7 pc. Can a
-
I have new 4s. If phone is stolen do i have GPS tracking feature?
I recently acquired my first iPhone. The 4s - everything is great. If the phone is lost or stolen while it is activated; do I have GPS tracking that will help locate the lost phone?
-
using this code now in the action script and it works great - only problem is, when I run it, the link opens in a new window instead of the current window. Can someone tell me how to fix this? var link:URLRequest = new URLRequest("home.html"); skip_b
-
No songs?????
My brother recently got an ipod shuffle, and he had to deselect a few songs from my itunes to put on his. When he did this a few songs were taken out from my ipod, but it shows that they are in my ipod but they do not play. For example if i click a s