Toronto23
Toronto23

Reputation: 319

What is the purpose of RAISE_APPLICATION_ERROR?

I understand that RAISE_APPLICATION_ERROR associates a message error which only has a meaning to the user. But can't the user just write a similar exception the following way?

DECLARE
e_negative EXCEPTION;


BEGIN
IF v_sid < 0 THEN
RAISE e_negative;
...

EXCEPTION
WHEN e_negative THEN
DBMS_OUTPUT.PUT_LINE ('An id cannot be negative');

Upvotes: 3

Views: 432

Answers (1)

Mureinik
Mureinik

Reputation: 311103

raise_application_error does more than print an error message to the console (like dbms_output.put_line does).

First, it's an actual error - it fails the statement, terminates the current block's execution, and propagates to outer blocks (similar to throw in Java or raise in Python).

Second, it actually returns this error regardless of the console. dbms_output's messages may be turned off or ignored, depending on the client. Raising an application error allows you to return the details of the failure, regardless of the client.

Upvotes: 8

Related Questions