1

Can anyone please explain me why the answer in the following code is "Inside OTHERS" not "ORA -20002 5 is greater than 3"

BEGIN
IF 5>3 THEN
    RAISE_APPLICATION_ERROR (-20002, ‘5 is greater than 3’);
END IF;
EXCEPTION
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE(‘Inside OTHERS’);
END;

Answer: Inside OTHERS

2 Answers 2

4

Because you are catching the raised exception and printing in console the message "Inside OTHERS".

I think you need something like this:

DECLARE
   comparison_error exception;
   PRAGMA EXCEPTION_INIT(comparison_error, -20002);
BEGIN
IF 5>3 THEN
    RAISE_APPLICATION_ERROR (comparison_error, '5 is greater than 3');
END IF;
EXCEPTION
    WHEN comparison_error THEN
        DBMS_OUTPUT.PUT_LINE('SQLERRM: ' || SQLERRM);
    WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('Inside OTHERS');
END;
0
0

Try this :

BEGIN
IF 5>3 THEN
RAISE_APPLICATION_ERROR (-20002, '5 is greater than 3');
END IF;
EXCEPTION
WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(sqlerrm);
    DBMS_OUTPUT.PUT_LINE('Inside OTHERS');
END;

Not the answer you're looking for? Browse other questions tagged or ask your own question.