1、概念

在程序执行过程 出现的错误 

2、举例

declare
       var_name   s_emp.first_name%type; 
begin
       select  first_name  into var_name from  s_emp  where id=44;
       dbms_output.put_line(var_name);
exception
       when  others   then
       dbms_output.put_line('have  exception');
end;
/  

3、预定义了 一些常见的操作异常

declare
        var_name   s_emp.first_name%type; 
begin
        select  first_name  into var_name from  s_emp  where id=4;
        dbms_output.put_line(var_name);
        select  first_name  into var_name from  s_emp  where id>4;
        dbms_output.put_line(var_name); 
exception
        when    NO_DATA_FOUND  then 
        dbms_output.put_line('no emp found');
        when  TOO_MANY_ROWS  then 
        dbms_output.put_line('too many emp');
        when  others   then
        dbms_output.put_line('have  exception');                 
end;
/  
      当写plsql程序 时要分析程序可能会出现哪些异常  然后根据系统预定义的异常
   进行相应的处理  程序的最后一般使用 others  作为最后的异常捕获处理。

4、用户自定义异常

1.定义异常
根据系统中  可能出现问题  使用异常描述出来 

2.抛出异常 
用户根据 条件 抛出   满足什么样的条件 就抛出什么样的异常 

3.捕获异常 

4.处理异常 
针对不同异常  作出相应的处理 

5 举例

declare
        empexception     exception;
        deptexception     exception;
begin
         if  1=2  then 
              raise   empexception; 
         end if;
         if  1=1  then 
              raise  deptexception; 
         end if; 
         dbms_output.put_line('app continue');                  
exception
          when   empexception  then
          dbms_output.put_line('emp exception');
          when   deptexception  then
          dbms_output.put_line('dept exception');     
end;
/