cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle method based exceptions in webdynpro abap?

suman_kumar16
Participant
0 Kudos

Hi ,

    I want to raise an exception from my method.....I am doing division operation inside my method...when I am entering a very large amount , that time I am getting run time error.....please someone help me to catch this exception and display on browser.

Thanks & Regards

Suman Kumar

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Suman,

You can catch the arithmetic exception by using exception class CX_SY_ARITHMETIC_ERROR as below

Sample code:


          data lv_ex_msg               type string.

          data lx_sy_error              type ref to CX_SY_ARITHMETIC_ERROR.

          try.

               "here goes your code

          catch CX_SY_ARITHMETIC_ERROR into lx_sy_error.

                           "  you can get exception text as below

                         lv_ex_msg = lx_sy_error->get_text( ).

                         or

                       

                     " lv_ex_msg = lx_sy_error->get_longtext( ).

          endry.

Hope this helps you.

Regards,

Rama

suman_kumar16
Participant
0 Kudos

Hi rama ,

            Thanks for your quick reply......I have one doubt ....Do I need to declare anything in exception tab of method (global class I am talking)..

Thanks

Suma Kumar

ramakrishnappa
Active Contributor
0 Kudos

Hi Suman,

No need to use exception tab of method in your case.

You are just catching the text of exception.

....

We use the exception tab of method when we need to return some exception raised in the method to other method.


Example:

let us say we have methods : method_1 with exception EX_1 & other method method_2 which calls the method_1 inside

method method_2.

    

          call method method_1

               exporting

                 a = lv_p

               exceptions

                    ex_1 = lx_1.

endmethod.

Hope this helps you.

Regards,

Rama

suman_kumar16
Participant
0 Kudos

Thanks a lot Rama....yours reply always a gr8 help

ramakrishnappa
Active Contributor
0 Kudos

You are welcome

Answers (0)