Quantcast
Channel: SCN: Message List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 9165

Re: Exception Handling in Stored Procedure

$
0
0

Hello Sakshi,

 

you can used the nested block exception handling options in case you wanna just declare an exit handler for a specific block. What I do not understand is which coding you need to write twice? In case you just surround the block with an exit handler for which an exception has to be handled it should not be necessary to write coding twice (in specific cases it could be that single statements have to be surrounded).

 

Following a little example with two block levels:

PROCEDURE "_SYS_BIC"."test.procedures::test"   ( out e_level1 nvarchar(10),    out e_level2 nvarchar(10),    out e_errorl1 nvarchar(1),    out e_errorl2 nvarchar(1) )  LANGUAGE SQLSCRIPT  SQL SECURITY INVOKER  as
begin  declare test_cond_l1 condition;  declare exit handler for test_cond_l1    begin      e_errorl1 := 'X';    end;  begin    declare test_cond_l2 condition;    declare exit handler for test_cond_l2      begin        e_errorl2 := 'X';      end;          signal test_cond_l2;          e_level2 := 'reached'; -- not reached, because of test_cond_l2 signal  end;    e_level1 := 'reached'; -- reached, because test_cond_l2 signal was handled in nested block
end;

On the first level block parameter e_level1 is set to "reached". In the second level block, parameter e_level2 is not set to the value, because before the test_cond_l2 signal is fired. But because this is handled in the nested block e_level1 is set afterwards, because the processing goes one after the nested block.

In case a specific exception handling logic is necessary several times it can be encapsulated in a procedure.

 

Best Regards,

Florian


Viewing all articles
Browse latest Browse all 9165

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>