Exceptions Raised in the Exception Handler : Raise Exception « PL SQL Programming « Oracle PL/SQL Tutorial






SQL>
SQL> create or replace procedure p_validatezip (i_zipCode VARCHAR2)
  2  is
  3       e_tooShort EXCEPTION;
  4       e_tooLong  EXCEPTION;
  5       e_badZip   EXCEPTION;
  6       pragma exception_init(e_badZip, -20998);
  7       v_tempZip NUMBER;
  8  begin
  9       if length(i_zipCode)< 5 then
 10         Raise e_tooShort;
 11       elsif  length(i_zipCode)> 6 then
 12         Raise e_tooLong;
 13       end if;
 14       v_tempZip := to_number(i_zipCode);
 15  exception
 16       when e_tooLong then
 17        raise e_badZip;
 18     when e_tooShort then
 19        raise e_badZip;
 20     when VALUE_ERROR then
 21        raise e_badZip;
 22     when e_badZip then
 23        DBMS_OUTPUT.put_line('problem with Zip');
 24        raise;
 25  end;
 26  /

Procedure created.

SQL> begin
  2      p_validatezip('9406123123');
  3  end;
  4  /
begin
*
ERROR at line 1:
ORA-20998:
ORA-06512: at "JAVA2S.P_VALIDATEZIP", line 17
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at line 2


SQL>








24.16.Raise Exception
24.16.1.User-Defined Errors
24.16.2.Raise Exception in a function
24.16.3.Raising an Exception Local PL/SQL Block
24.16.4.Avoiding exceptions raised in declaration part and exception handler
24.16.5.Raising an Exception in the Declaration Section
24.16.6.Exceptions Raised in the Exception Handler
24.16.7.Raising NO_DATA_FOUND
24.16.8.Raising a custom exception
24.16.9.Using WHEN OTHERS clause
24.16.10.Using SQLCODE and SQLERRM
24.16.11.Propogating a Server-side Customized Error Number and Error Message to client program using PRAGMA EXCEPTION_INIT