‎2010 Aug 18 9:00 AM
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
‎2010 Sep 28 8:42 AM
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.
‎2010 Sep 28 9:43 AM
@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
‎2010 Sep 28 9:47 AM
All this doen't apply for a cl_ujc_cmtmanager object. How can you check if such an object exists or not?
‎2010 Sep 28 9:51 AM
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?
‎2010 Sep 28 9:53 AM
> @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).
‎2010 Sep 28 9:55 AM
Eddy, could you paste code snippet from your program?
It would be easier to analyze.
‎2010 Sep 28 9:57 AM
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.
‎2010 Sep 28 10:03 AM
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?
‎2010 Sep 28 10:06 AM
Yes, appsetid and appl_id is user input
It is a standard SAP BW constructor
‎2010 Sep 28 10:13 AM
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.