Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Raise Application Error confusion

TinaAug 12 2020 — edited Aug 20 2020

Hi Gurus,

  I have 3 procedures below.

  Proc1 and Proc2 are fine, when count > 0, user is getting exception.

  I have confusion in Proc3, where I am raising exception but procedure is silently ending successfully.

  I was under the impression that it should have raised exception to user, why control is going to when_others_then in this case and procedure is successful?

  Should we not use raise_application_error along with when others then ?

CREATE OR REPLACE PROCEDURE TEST_PROC1

AS

   V_COUNT NUMBER := 1;

   E_EXCEPTION EXCEPTION ;

BEGIN

IF V_COUNT >0 THEN                                   

   RAISE E_EXCEPTION;

END IF;

  EXCEPTION

  WHEN E_EXCEPTION THEN

      RAISE;

  WHEN OTHERS THEN

      DBMS_OUTPUT.PUT_LINE('Error Occured');

END;

CREATE OR REPLACE PROCEDURE TEST_PROC2

AS

  V_COUNT NUMBER := 1;

BEGIN

IF V_COUNT >0 THEN                                   

   RAISE_APPLICATION_ERROR(-20102,'Difference in VW_CHECK_NON_ZERO_BAL_MTH.Please check');

END IF;

END;

CREATE OR REPLACE PROCEDURE TEST_PROC3

AS

  V_COUNT NUMBER := 1;

BEGIN

IF V_COUNT >0 THEN                                   

   RAISE_APPLICATION_ERROR(-20102,'Difference in VW_CHECK_NON_ZERO_BAL_MTH.Please check');

END IF;

  EXCEPTION WHEN OTHERS THEN

  DBMS_OUTPUT.PUT_LINE('Error Occured');

END;

This post has been answered by Saubhik on Aug 12 2020
Jump to Answer
Comments
Post Details
Added on Aug 12 2020
8 comments
547 views