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

Catch assertion_failed on create object

Former Member
0 Likes
2,585

Hi,

I create an object based on user input. When the user makes a typo, I get an assertion_failed dump, although I've encapsulated it wit a try catch on cx_root.

How can I catch an assertion_failed in order to prevent a dump?

Eddy

10 REPLIES 10
Read only

former_member182670
Contributor
0 Likes
1,726

Failed assertion means that some invariant was not fulfilled and the code cannot continue any further.

I think you should check the data before creating the object and make sure you pass the right data.

If the author of the object coded an assertion he meant that the condition should be fulfilled in order to create the object.

Also quote from documentation:

If the result of log_exp is false, for an always active assertion (without the addition ID) an untreatable exception is triggered and the program terminates with the runtime error ASSERTION_FAILED.

Read only

MarcinPciak
Active Contributor
0 Likes
1,726

@Eddy

You can do a simple check before creating instance of this class


DATA: gr_typedescr  TYPE REF TO cl_abap_typedescr,
      gr_obj        TYPE REF TO object.
DATA: gt_params     TYPE abap_parmbind_tab.

CALL METHOD cl_abap_typedescr=>describe_by_name(
EXPORTING
  p_name         = 'CL_GUI_ALV_GRID2'
RECEIVING
  p_descr_ref    = gr_typedescr
EXCEPTIONS
  type_not_found = 1
  OTHERS         = 2 ).

IF sy-subrc = 0.
  CREATE OBJECT gr_obj TYPE ('CL_GUI_ALV_GRID2')
    PARAMETER-TABLE gt_params.
ENDIF.

@Tomek

If the result of log_exp is false, for an always active assertion (without the addition ID) an untreatable exception is triggered and the program terminates with the runtime error ASSERTION_FAILED.

Actually this depends on configuration made in SAAB . The processing might still go on if other config option is set.

Regards

Marcin

Read only

0 Likes
1,726

All this doen't apply for a cl_ujc_cmtmanager object. How can you check if such an object exists or not?

Read only

0 Likes
1,726

As long as it is a valid class in the repository, then the above will work. But this class seems not to exist. How you are going to create its instance then?

Read only

0 Likes
1,726

> @Tomek

>

If the result of log_exp is false, for an always active assertion (without the addition ID) an untreatable exception is triggered and the program terminates with the runtime error ASSERTION_FAILED.

>

> Actually this depends on configuration made in SAAB . The processing might still go on if other config option is set.

>

> Regards

> Marcin

The prerequisite for using SAAB is the ID addition. I referred to "always active assertions" (without ID).

Read only

0 Likes
1,726

Eddy, could you paste code snippet from your program?

It would be easier to analyze.

Read only

0 Likes
1,726

It is as simple as this:

DATA:

lo_cmt_manager TYPE REF TO cl_ujc_cmtmanager.

TRY.

CREATE OBJECT lo_cmt_manager

EXPORTING

i_appset_id = appsetid

i_appl_id = appl_id.

...

CATCH cx_root INTO lox_ex_handler.

ENDTRY.

Read only

0 Likes
1,726

You get appsetid and appl_id from the users?

Could you please paste also relevant part of cl_ujc_cmtmanager constructor as I don't have this class?

Read only

0 Likes
1,726

Yes, appsetid and appl_id is user input

It is a standard SAP BW constructor

Read only

0 Likes
1,726

I don't have access to BW currently. But my point is that you should check in the constructor what are the conditions used in the ASSERT statement and make sure that your parameters fulfill these conditions before creating the object.