Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Where do i use RESUMABLE EXCEPTION?

SuhaSaha
Advisor
Advisor
0 Kudos

Hello SDNers,

I have the following construct in my code:


  TRY .
      val1    = persist_class->get_value( key1 ).

      val2    = persist_class->get_value( key2 ). " --> exception is raised here

      val3    = persist_class->get_value( key3 ).

    CATCH exception.

  ENDTRY.

I want the next statement


val3    = persist_class->get_value( key3 ).

to be executed after the exception has been handled.

I thought of using "resumable exceptions". So I read the SAP documentation on the topic & then debugged the program DEMO_CATCH_EXCEPTION.

IMO "resumable" is w.r.t. the procedure which RAISES the exception & not the HANDLER. Is my understanding correct? If yes, then what is their utility?

Thanks for your replies.

BR,

Suhas

1 ACCEPTED SOLUTION

former_member182466
Contributor
0 Kudos

Your understanding is correct. The reason for resumable exceptions it to give the calling program the control if the error is fatal or not.


If you want the behavior you describe you raise the resumable exception in the get_value( ) method and when it comes back you perform a RETURN to exit the method. This will then continue with the next command after the method call.


You can also do it without resumable exceptions by putting every call to get_value( ) in its own TRY-CATCH.


The documentation is pretty clear:

There are two different exception handling cases:

  1. The context in which the exception was raised is deleted completely before or after handling. This removes all procedures from the memory (and also their local data, which was called from the handler context and which caused the exception); handling is resumed depending on how the handler is exited.

  2. The context in which the exception was raised is retained and the program is resumed after the statement that raised the exception.

A prerequisite for the second case are resumable exceptions. These exceptions must be raised with the addition RESUMABLE of the statement RAISE EXCEPTION and declared using the addition RESUMABLE in the interface of the procedures from which they were propagated. The statement RESUME is used to resume the program.

The documentation of the RESUME command:

This statement exits the CATCH handling of a resumable exception and resumes processing after the statement that raised the exception. This statement can only be executed in a CATCH block of a TRY control structure for which the addition BEFORE UNWIND is declared. When exception handling is exited using RESUME, the context of the exception is not deleted and any CLEANUP blocks are not executed.

3 REPLIES 3

former_member182466
Contributor
0 Kudos

Your understanding is correct. The reason for resumable exceptions it to give the calling program the control if the error is fatal or not.


If you want the behavior you describe you raise the resumable exception in the get_value( ) method and when it comes back you perform a RETURN to exit the method. This will then continue with the next command after the method call.


You can also do it without resumable exceptions by putting every call to get_value( ) in its own TRY-CATCH.


The documentation is pretty clear:

There are two different exception handling cases:

  1. The context in which the exception was raised is deleted completely before or after handling. This removes all procedures from the memory (and also their local data, which was called from the handler context and which caused the exception); handling is resumed depending on how the handler is exited.

  2. The context in which the exception was raised is retained and the program is resumed after the statement that raised the exception.

A prerequisite for the second case are resumable exceptions. These exceptions must be raised with the addition RESUMABLE of the statement RAISE EXCEPTION and declared using the addition RESUMABLE in the interface of the procedures from which they were propagated. The statement RESUME is used to resume the program.

The documentation of the RESUME command:

This statement exits the CATCH handling of a resumable exception and resumes processing after the statement that raised the exception. This statement can only be executed in a CATCH block of a TRY control structure for which the addition BEFORE UNWIND is declared. When exception handling is exited using RESUME, the context of the exception is not deleted and any CLEANUP blocks are not executed.

0 Kudos

Hello Gerrit,

Thanks for the explanation. The key to resumable-exception is that the processing "resumes" after the exception has been raised, i was kinda blind to this fact.


If you want the behavior you describe you raise the resumable exception in the get_value( ) method and when it comes back you perform a RETURN to exit the method. This will then continue with the next command after the method call.

Actually i didn't need a RETURN. If there are no executable statements after the exception, the flow returns back to the caller.

You can also do it without resumable exceptions by putting every call to get_value( ) in its own TRY-CATCH.

I know that, just didn't wanna use it. If we have resumable-exception, why not use it

Now that i've a better understanding of res. exception, the next question that pops-up in my mind is -


Shouldn't we define all the exceptions as "resumable"?

After all the caller should decide whether the error is fatal or not, isn't it?

Best,

Suhas

To answer your last question: no.

Some exceptions you just cannot recover from, e.g. a wrong value in a parameter.