Download Exception Handling in SAP ABAP PDF

TitleException Handling in SAP ABAP
File Size207.7 KB
Total Pages19
Document Text Contents
Page 1

Page 10

the journey. This can be compared to an exception which affects the program so

deeply, that it is best to end the program.

So before handling an exception, you have to first get a clear idea of how deeply a particular

error impacts the component you develop. As I have told you before, you should avoid

assumptions about the global layout of the components that call you. If it is your task to

provide the address of a customer and there is none for a particular name, delegate the

exception to your caller. It is up to the caller to decide how to go on without an address.

Whether or not to Use an Exception

Stepping back a bit from the specific ways in which you deal with an exception once it occurs,

you are faced with a basic decision of whether or not to treat a situation as an exception at all.

Except for a syntactical error, a situation usually does not come labeled as an exception. But it

is up to you to assess it as an exceptional situation or as part of the normal course of events. As

a rule of thumb you might say: If some situation is within the realm of expectation, you had

better use a return code to indicate it. Reserve exceptions for those situations that exceed the

range of the normal.

The Cleanup Section

Once an exception is raised the control flow continues with the next suitable handler which

means that the normal flow of control is changed. There may be good reasons to handle some

exceptions on a high level in the call hierarchy. This would have the consequence that one or

many procedures end prematurely which in turn may leave the application in an inconsistent

state or keep resources unreleased. These are the situations the cleanup clause is designed to

deal with.

The cleanup section is between the last handler and the ENDTRY. It is processed only if some

conditions are fulfilled:

 An exception is raised in the protected area.

 The exception is not dealt with in this TRY-ENDTRY block, but somewhere up in the

call hierarchy.

So let us change our example a bit and have a look at how a CLEANUP block works:

Similer Documents