Oracle PL/SQL - Handle several exceptions

Description

Handle several exceptions

create or replace
procedure p_validateZip (i_zipCode_tx VARCHAR2)
is
  e_tooShort EXCEPTION;                                     
  e_tooLong  EXCEPTION;                                     
  e_badZip   EXCEPTION;                                     
  pragma exception_init(e_badZip,-20998);                   
  v_tempZip_nr NUMBER;
Begin
  if length(i_zipCode_tx)< 5 then
     Raise e_tooShort;                                      
  elsif  length(i_zipCode_tx)> 6 then
     Raise e_tooLong;                                       
  end if;

exception
   when e_tooLong then                                        
       insert into t_LogError (error_tx)values('long zip');
       raise e_badZip;
   when e_tooShort then                                       
       insert into t_logError (error_tx)values('short zip');

   when value_error then                                      
       insert into t_LogError (error_tx)values('non-numeric zip');
       raise; 
end;

Related Topic