user3682983
user3682983

Reputation: 177

PL/SQL Exceptions

begin

  begin

     do something;

  exception

    when no_data_found then
      raise_application_error(-20000,"Message");

  end;

 exception

    when others then
        raise_application_error(-20000,"Other message");

 end;

My problem is when the compiler catches the "Message" error it alsos catches the "Other message" error. Why does it happen?

Upvotes: 0

Views: 94

Answers (1)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

try to put them in the same exception block.

If you put when others in a separated block, it will alwasy be raised, as... there's no already catched exception to exclude from others in that block.

From doc

The WHEN OTHERS clause is used to trap all remaining exceptions that have not been handled by your Named System Exceptions and Named Programmer-Defined Exceptions.

So

exception

    when no_data_found then
      raise_application_error(-20000,"Message");

    when others then
      raise_application_error(-20000,"Other message");

end;

Upvotes: 4

Related Questions