Skip to Content

Try.Catch problem with CATCH SYSTEMEXCEPTIONS

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?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Apr 14, 2010 at 08: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.

    Catch

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • Jul 21, 2010 at 11:24 AM

    Thanks for all of your replies!

    Add comment
    10|10000 characters needed characters exceeded