Application Development and Automation 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: 
Read only

regarding try and catch

Former Member
0 Likes
559

hi i want to know what is try and catch. but i dont know oops concept that much . can any one help??? and how to use this in the program ?? give me one example.

hi i want to know what is try and catch. but i dont know oops concept that much . can any one help??? and how to use this in the program ?? give me one example.

2 REPLIES 2
Read only

Former Member
0 Likes
514

Hi,

Basic form

TRY.

Effect

You catch class-based exceptions in the statement block enclosed by the TRY and ENDTRY statements. To catch these exceptions, you define handlers within the specified TRY block. You introduce a handler using a CATCH statement, followed by the exception classes to be caught and the associated handler code. After the CATCH clauses, you can declare a CLEANUP clause. The statements in the latter clause will be executed if an exception is caught outsidethe TRY block. The structure of the TRY block is as follows:

TRY.

... guarded section

CATCH cx11 ... cx1n [INTO ex1].

... handlers for exceptions cx11 to cx1n

CATCH cx21 ... cx2m [INTO ex2].

... handlers for exceptions cx21 bis cx2m

... other handlers

CLEANUP.

... cleanup block

ENDTRY.

The TRY block is split into different sections using the CATCH and CLEANUP clauses.

Regards,

Omkar.

Read only

Former Member
0 Likes
514

Hi!

TRY-CATCH-ENDTRY can be used to handle catchable exception, for example a division by 0. If you divide a number with 0, basically you will have a short dump. Using TRY-CATCH, oyu can continue your program run and will not have dump.

Example:

TRY.

SORT T_ERGEB-MSG_T_SAP_ACTIVITY-ITEM DESCENDING.

DELETE ADJACENT DUPLICATES FROM T_ERGEB-MSG_T_SAP_ACTIVITY-ITEM.

CALL METHOD ZCO_SAP_ACTIVITY_TOMX=>EXECUTE_ASYNCHRONOUS

EXPORTING

OUTPUT = T_ERGEB

CONTROLLER = L_CONTROLLER.

COMMIT WORK.

CATCH CX_AI_SYSTEM_FAULT INTO L_SYS_EXCEPTION.

SY-MSGV1 = L_SYS_EXCEPTION->ERRORTEXT.

SUBRC = 1.

EXIT.

ENDTRY.

Regards

Tamá