Skip to main content
Solved

Handling custom exceptions within events

  • January 22, 2020
  • 1 reply
  • 1791 views

Forum|alt.badge.img+2

Hello,

I have made an event that throws an error message to the user, using the error_sys.record_general function, based on some criteria set in the event, which triggers on a change in the status of the object. 

error_sys.record_general( 'SomeLogicUnit', 'SOMEERRORMSG: this is an error message');

I am in the process of creating another event that will change the status of the object, but I am wondering if it is possible to catch the exception raised in the other event, and handle it separately? 

Without handling the event, and running the event manually in a DBMS, the procedure completes, but returns

ORA-20110: SomeLogicUnit.SOMEERRORMSG: this is an error message

 

My event would look something like this:

BEGIN

 --change status on object, which may cause an error to be raised in the other event

EXCEPTION
 WHEN ... THEN
 -- handle the exception raised from the other event
END;

If I specify “EXCEPTION WHEN others THEN … “ I will catch the error raised in the other event, but I won’t know the source of the error, or the error itself for that matter. Is there a way for me to handle that specific error, or would I have to declare and raise the error in the source event manually? 

Best answer by Mathias Dahl

Yes, you can catch a known exception, based on a number that you know. Have a read here (this is just one page that explains it, I am sure there are hundreds more):

https://docs.oracle.com/cd/B10501_01/appdev.920/a96624/07_errs.htm

Especially, have a look at this section:

Associating a PL/SQL Exception with a Number: Pragma EXCEPTION_INIT

Good luck!
 

View original
Did this topic help you find an answer to your question?

1 reply

Mathias Dahl
Superhero (Employee)
Forum|alt.badge.img+32
  • Superhero (Employee)
  • 2875 replies
  • Answer
  • January 24, 2020

Yes, you can catch a known exception, based on a number that you know. Have a read here (this is just one page that explains it, I am sure there are hundreds more):

https://docs.oracle.com/cd/B10501_01/appdev.920/a96624/07_errs.htm

Especially, have a look at this section:

Associating a PL/SQL Exception with a Number: Pragma EXCEPTION_INIT

Good luck!
 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings