‎2008 Jun 18 2:51 PM
Hi,
I have the following situation. Please help me how can i solve this.
I am catching the error into single exception class(
data:lr_exception TYPE REF TO cx_mdm_main_exception,.
CATCH cx_mdm_usage_error INTO lr_exception.
CATCH cx_mdm_provider INTO lr_exception.
CATCH cx_mdm_kernel INTO lr_exception.
CATCH cx_mdm_server_rc_code INTO lr_exception.
CATCH cx_mdm_not_supported INTO lr_exception.
Now i will pass the lr_exception to some other varible for error handling. There i need to know which type of error it is like usage_error or proverder error or kernel error or something like as follow.
If lr_exception type is cx_mdm_usage_error
-
do something
elseif lr_exception type is cx_mdm_provider
-- do something
endif.
How to do this kind of checking. Please suggest me if you have the soultion.
Thanks and Best Regards,
Vijay
‎2008 Jun 23 10:40 AM
Hi,
This should be simple.
In each exception class you can have a "static attribute" that defines the name of the class.
Now when you catch the exception you can determine which class it refers to by using this value.
For example:
TRY.
CASE lr_exception->class_id.
WHEN (cx_mdm_usage_error). -
> This can be a hardcoded value
do something..
WHEN (cx_mdm_provider).
do something.
WHEN OTHERS.
RAISE unsupported_object_type.
ENDCASE.
ENDTRY.
I hope this helps.
Regards,
Saurabh
‎2008 Jun 18 3:52 PM
Hello,
Please see the code bellow:
DATA:
vehicle type ref to vehicle,
plane_ref type ref to plane,
ship type ref to ship.
catch system-exceptions move_cast_error = 4.
vehicle ?= i_ref.
endcatch.
if sy-subrc = 0.
"working with vehicle
else.
"not a vehicle
endif.
catch system-exceptions move_cast_error = 4.
plane ?= i_ref.
endcatch.
if sy-subrc = 0.
"working with plane
else.
"not a plane
endif.
catch system-exceptions move_cast_error = 4.
ship ?= i_ref.
endcatch.
if sy-subrc = 0.
"working with ship
else.
"not a ship
endif.
This was extracted from the book ABAP Objects - An introduction to programming SAP applications from Horst Keller and Sascha Krüger.
Just change the catch mode to TRY and ENDTRY.
Regards.
‎2008 Jun 23 10:40 AM
Hi,
This should be simple.
In each exception class you can have a "static attribute" that defines the name of the class.
Now when you catch the exception you can determine which class it refers to by using this value.
For example:
TRY.
CASE lr_exception->class_id.
WHEN (cx_mdm_usage_error). -
> This can be a hardcoded value
do something..
WHEN (cx_mdm_provider).
do something.
WHEN OTHERS.
RAISE unsupported_object_type.
ENDCASE.
ENDTRY.
I hope this helps.
Regards,
Saurabh
‎2008 Jun 23 5:38 PM
Hi Vijay,
This is the siplest way to handle all your exceptions.You should go through this code. You can easily understanding.If any queries, ask me.
DATA: l_exceptions TYPE REF TO CX_ROOT,
l_excstring type string.
try.
catch l_exceptions into l_excstring.
case l_excstring.
WHEN cx_mdm_usage_error.
do something..
WHEN cx_mdm_provider.
do something.
WHEN cx_mdm_kernel
do something.
WHEN cx_mdm_server_rc_code.
do something.
WHEN cx_mdm_not_supported.
do something.
WHEN OTHERS.
RAISE unsupported_object_type.
ENDCASE.
ENDTRY.
If it useful, reward points.
Thank you,
Prasad G.V.K
‎2010 Dec 17 3:14 PM