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: 

exception

Former Member
0 Kudos

can anybody tell the exact procudure about exception handling in OOABAP.

1 REPLY 1

former_member199581
Active Participant
0 Kudos

Well, the OO exceptions handling it's described in three instructions:

TRY...CATCH...CLEANUP...ENDTRY.

Every method that can raise a class-based exception (you can recognize those classes because their prefix is CX instead of CL) must be called in a TRY...CATCH...ENDTRY block.

For example:


TRY.
  cl_salv_table=>factory( IMPORTING r_table = theTable
                                    CHANGING t_table = mytable ).
  CATCH cx_salv_msg.
* // Exception handling
ENDTRY.     

If the method FACTORY from class CL_SALV_TABLE raises an exception of the specified type (here, CX_SALV_MSG) the process branches to the CATCH block.

In it you can handle the exception (such as send a message, call another method, exit, or anything you want).

If, in this example, there wasn't any TRY...CATCH...ENDTRY block, process will be ended in a runtime error.

There is another statement, CLEANUP, that it's used if an exception is triggered inside your TRY...ENDTRY block, but caught by another CATCH instruction (i.e, inside the method FACTORY).

This will be called after the internal exception handling, leaving to you to perform cleanup tasks. Note that you cannot leave the CLEANUP block using exit commands (as RETURN, EXIT, LEAVE PROGRAM, etc..). The block must be totally performed and leaved with the ENDTRY statement.

Hope this is clear and helps you.

Roby.