Raise your own exception : Raise « PL SQL « Oracle PL / SQL






Raise your own exception

   
SQL>
SQL>
SQL> set echo off
SQL> set verify off
SQL> set define '&'
SQL>
SQL> prompt 'degrees F?:'
'degrees F?:'
SQL> accept temp default '100'

SQL> declare
  2    porridge_too_hot  exception;
  3    porridge_too_cold exception;
  4  begin
  5    case
  6      when '&temp' < 90.00 then raise porridge_too_cold;
  7      when '&temp' > 140.00 then raise porridge_too_hot;
  8      else null;
  9    end case;
 10
 11    dbms_output.put_line('just right');
 12
 13  exception
 14    when VALUE_ERROR then
 15      dbms_output.put_line('Please enter a numeric temperature (like 100)');
 16
 17    when porridge_too_hot then
 18      dbms_output.put_line('way too hot...');
 19
 20    when porridge_too_cold then
 21      dbms_output.put_line('way too cold...');
 22  end;
 23  /
just right

PL/SQL procedure successfully completed.

SQL>

   
    
  








Related examples in the same category

1.Raising an exception
2.Raising NO_DATA_FOUND Exception
3.RAISE_APPLICATION_ERROR
4.Raise different exception depends on value input
5.Raise exceptions for wrong parameters
6.Print out an error message
7.Raises and manages a standard anonymous block PL/SQL program error.
8.This procedure demonstrates the use of RAISE_APPLICATION_ERROR.
9.Setting the message dynamically