04-14-2010 9:02 AM
Hi,
I'm using this example coding
IF sy-batch <> ''.
CATCH SYSTEM-EXCEPTIONS
dataset_too_many_files = 90
open_dataset_no_authority = 91
dataset_write_error = 92
dataset_cant_close = 93
dataset_read_error = 94
.
ENDCATCH.
ELSE.
o_material = zcl_sales_material_base=>factory( ).
TRY.
o_material->reload_matnr(
i_matnr = l_tab_daemon_input-matnr
i_vkorg = l_tab_daemon_input-vkorg
i_vtweg = l_tab_daemon_input-vtweg
).
CATCH zcx_sales_material .
sy-subrc = 99.
ENDTRY.
ENDIF.
The code itself should not matter, however, the syntax check gives me the error:
TRY and CATCH SYSTEM-EXCEPTIONs cannot be used simultaneously
.
While I understand this error when using nested coding like this
TRY.
CATCH SYSTEM-EXCEPTIONS
dataset_too_many_files = 90
open_dataset_no_authority = 91
dataset_write_error = 92
dataset_cant_close = 93
dataset_read_error = 94
.
ENDCATCH.
CATCH zcx_sales_material .
sy-subrc = 99.
ENDTRY.
ENDIF.
I don't understand why the parser throws the mentioned error in the coding on the top. IMO the CATCH..ENDCATCH and TRY..ENDTRY are two separate blocks independent of each other. So what's the deal here?
04-14-2010 9:29 AM
Please read this
The TRY block contains the application coding whose exceptions are to be handled. This statement block is processed sequentially. It can contain further control structures and calls of procedures or other ABAP programs.
If an exception occurs in the TRY block or in a procedure called up here, the system starts by searching for a CATCH statement of the same TRY-ENDTRY structure. It then searches from the inside out for a CATCH statement in any enclosing TRY-ENDTRYstructures that handle the event. The system may call this handler. If the system does not find a handler, but the TRY-ENDTRY structure is contained in a procedure, it tries to propagate the exception to the caller (see also Propagating Exceptions). Exceptions cannot be propagated in any processing blocks without a local data area (event blocks, dialog modules). A runtime error occurs immediately if the handler is missing.
If no exceptions occur in the TRY block, program execution is continued directly after ENDTRY after the block has been completed.
This i have taken from the following documentation.
a®
04-14-2010 9:29 AM
Please read this
The TRY block contains the application coding whose exceptions are to be handled. This statement block is processed sequentially. It can contain further control structures and calls of procedures or other ABAP programs.
If an exception occurs in the TRY block or in a procedure called up here, the system starts by searching for a CATCH statement of the same TRY-ENDTRY structure. It then searches from the inside out for a CATCH statement in any enclosing TRY-ENDTRYstructures that handle the event. The system may call this handler. If the system does not find a handler, but the TRY-ENDTRY structure is contained in a procedure, it tries to propagate the exception to the caller (see also Propagating Exceptions). Exceptions cannot be propagated in any processing blocks without a local data area (event blocks, dialog modules). A runtime error occurs immediately if the handler is missing.
If no exceptions occur in the TRY block, program execution is continued directly after ENDTRY after the block has been completed.
This i have taken from the following documentation.
a®
04-14-2010 12:24 PM
Thanks for your reply!
I know about the processing of a TRY..ENDTRY block and the handling when there are nested TRY..ENDTRY blocks, however this does not explain why I can't have a CATCH SYSTEM-EXCEPTIONS..ENDCATCH block and a following TRY..ENDTRY block, in one FORM for example, without nesting them.
In the meantime I've found this restriction in the help, too, and as a workaround to change all CATCH SYSTEM-EXCEPTIONS..ENDCATCH blocks into appropriate TRY..ENDTRY blocks with similar exception classes, which works fine for me.
04-14-2010 12:31 PM
Hello Michael,
I thought about proposing you to replace CATCH SYSTEM-EXCEPTIONS by relevant TRY ... ENDTRY blocks. But i was curious why the compiler was giving the syntax error
Even SAP suggests the same as CATCH SYSTEM-EXCEPTIONS is an obsolete statement.
The handling of catchable runtime errors using CATCH SYSTEM-EXCEPTIONS is obsolete and should be replaced with a TRY control structure. Since class-based exceptions are assigned to all catchable runtime errors, this is possible without restriction. In particular, the exceptions can be passed from procedures using a TRY control structure.
Cheers,
Suhas
Edited by: Suhas Saha on Apr 14, 2010 5:02 PM
05-02-2014 10:39 AM
If you are looking for classes that are assigned to system exceptions, you can look directly into documentation: ABAP Keyword Documentation (Assignment of Catchable Runtime Errors to Exception Groups).
For instance, system exception OPEN_DATASET_NO_AUTHORITY can be catched with CX_SY_FILE_AUTHORITY exception class or its associated superclass CX_SY_FILE_ACCESS_ERROR.
Best regards,
Gabriel
07-21-2010 12:24 PM