• Run-time errors can be handled in some useful way rather than getting system specific message and terminating program abruptly.
  • The following example explains handling of named exceptions.
  • INPUT:
  • DECLARE
  •                   Declare required variables...
    •                         no Account.ano%TYPE;
    •                         bal Account.bal%TYPE;
      •             branch Account.bname%TYPE

    BEGIN

--read an account number, balance, and branch name    for new record...

                  no      := &no;

                 bal      := &bal;

                 branch := &branch;

        --insert record into Account table ...

INSERT INTO Account VALUES (no, bal, branch);

                        --commit and display message confirming insertion...

                                COMMIT;

                                dbms_output.put_line (‘Record inserted

                                successfully...’);

        Output 1:

                  Enter value for no: ‘A01’

                        Enter value for bal: 5000

                        Enter value for branch: ‘vvn’

                        Record inserted successfully...

        Output 2:

                  Enter value for no: ‘A01’

                        Enter value for bal: 10000

                        Enter value for branch: ‘ksad’

                        Duplicate value found for primary key.

  • Instead of displaying system specific error message, user specified error message is displayed on encountering duplicate value ‘A01’ for account number.