Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to throw a exception in function

How can I handle the exception in a function call? It has a separate function returning 1 or 0 depending on the argument used.

If the function is_valid_eventTypesGeographicAddress throws me 0 I want to throw an exception.

I have no idea how to do this in this syntax.

select is_valid_eventTypesGeographicAddress (in_type) from dual ,
             exception WHEN 0 then return  ('Invalid geographic address type');

Code does not compile.

like image 297
Grafik Krystian Avatar asked Sep 04 '26 00:09

Grafik Krystian


1 Answers

You can use PL/SQL and its RAISE_APPLICATION_ERROR procedure to throw an exception. Here's an example:

declare
  myResult number;
begin
  myResult := is_valid_eventTypesGeographicAddress (in_type);
  if myResult = 0 then
    raise_application_error(-20000, 'Invalid geographic address type');
  end if;
end;
like image 148
Pavel Smirnov Avatar answered Sep 06 '26 14:09

Pavel Smirnov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!