Application Development 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: 

Regarding exception ..

former_member187400
Active Contributor
0 Kudos

Dear friends,,

Could you kindly help me please to share your experience .. ??

I want to know how to raise exception in program (SE38).

I insert code for :

try

........

........

catch cx_root.

............... (1).

endtry.

That's "try-catch" working when there is error. The program will not exit directly. But the problem, i will not know if there is a problem, because the program run smoothly as if it were not error.

My solution is:

I still wanna raise an error when error's happening, but i will catch what's transaction no that's getting error.

< i plan to insert code to raise that error in point (1) >

But i don't know how to raise the error in the program (SE38).

Could you help me what command that can raise the error (and the program will exit directly) ????

Really need your help please ..

Regards,

Niel

1 ACCEPTED SOLUTION

rainer_hbenthal
Active Contributor
0 Kudos

If i understand you correctly, you have to put the appropriate code in the catch-branch.

Either raise another exception

RAISE EXCEPTION TYPE ....

or put a Message like this:

Message 'Error xyz found doing abc' type 'A'.

Both will terminate you program with a roll back and a sys abend. You can put other code which is suitable for you, of course.

10 REPLIES 10

rainer_hbenthal
Active Contributor
0 Kudos

If i understand you correctly, you have to put the appropriate code in the catch-branch.

Either raise another exception

RAISE EXCEPTION TYPE ....

or put a Message like this:

Message 'Error xyz found doing abc' type 'A'.

Both will terminate you program with a roll back and a sys abend. You can put other code which is suitable for you, of course.

0 Kudos

Thanks Rainer for your quick response.


  " i've put the raise command like you suggest but i get error. 
  " the error is : 
  " Old and new exceptions cannot be used the same time.

  try. 

  catch cx_root. 
     RAISE EXCEPTION TYPE CX_ROOT
  endtry. 

Perhaps i miss something there, could you write the complete one please .. ??

Regards,

Niel.

0 Kudos

Hi,

an exception is nothing else but a special class. The caller of an exception can deliver information to that class like "Hey, i cant go on further cause the database server isnt available".

Is this exception is not catched in your program, it will cause a sys abend delivering this inforation to the abend where you can read it.

if you wanna catch this exception because you want your own things to be taken place when certain erros occur you have to use the try / catch / endtry command setting.

So it does not make sense to catch an exception when the only thing to do is to throw the same exception again. You can skip that catch branch and the result will be the same: a sys abend.

Here is some code on how i am catching exceptions:


DATA cxr type ref to cx_root.


  TRY.
//do normal stuff here

    CATCH cx_sy_file_access_error INTO cxr.
      serror = cxr->get_text( ).
      MESSAGE serror TYPE 'E'.

    CATCH cx_sy_conversion_error INTO cxr.
      serror = cxr->get_text( ).
      MESSAGE serror TYPE 'E'.

  ENDTRY.

If there is a file access error, i'll put the error mestage to the customer, E will end the program without giving an abend.

Hope its now a little bit clearer´

0 Kudos

Dear Rainer,

Thaks a lot for your quick response ..

My appreciation has been delivered as my thanks to you ..

I have tried it, but it still come error .. It said : Message using ( XXX )..

Honestly Rainer ..

This program is user-exit; it's not related to customer directly ..

Usually, if we had error, we know the error from tcode : ST22. But in ST22 we don't have the trx no; so difficult to fix the data.

Using this,

I expect, the error still goes to tcode st22 (user-exit is not completed). But i can catch the trx no (for trx no, i've already found how to make it, but i still don't know to go out from program and put the message in ST22).

Could you help me again Rainer .. ??

Still need the guidance.

Regards,

Niel.

0 Kudos

Thats very easy: Skip the try/catch/endtry if you dont wanna handle the exception in your exit.

Just write your code as usual, if any of these statements will throw an exception and it is not handled anywhere in the program you will end up in st22.

So instead of


try.
  stmt1.
  stmt2.
  stmt3.

  catch.
    ....

endtry.

just write


  stmt1.
  stmt2.
  stmt3.

Programming your own handler for an exception is not mandantory. the try statemtent is only necessary if you want to handle the exceptiion by your own.

if you want to throw an exception in your userexit you can do it that way


raise exception type <your exception choce here>.

0 Kudos

Dear Rainer,

Tks a lot for your response..

Perhaps, right now you get confused .. #$%^&* :p..

But thanks for your concern up to now.

If we use the absolute way (with out try - catch), i won't get the transaction no in st22. It only mentions what the error is, but i don't know the error is coming in what transaction no is.

So the solution is, i insert the try - catch ..

where in the catch area, i will write the transaction no in the table so that i can get the transaction no and fix the data there.

But the other requirement..

I still wanna make this user exit get error, so that we as an IT/user can aware that program is going error.

Hopefully you're not getting bored ..

Still need your clues ..

Regards,

Niel.

0 Kudos

One question to clarify this:

With that try....endtry... are you trying to catch an internal or an homewritten exception? Who ist trowing this exception? (ok thats now two questions)

0 Kudos

What the hell has the second link to do with try/catch/endtry and exceptions? Nothing. Avoid Posting of unsuitable links, read what is beeing answered and givbe suitable answers. Useless Links can be found in Google.

former_member187400
Active Contributor
0 Kudos

Rainer,

I'd like to say thanks ..

My problem has solved completely ..

I still use try-catch method ..

But in the catch area, i use message using type 'X'.

With that type, it will get out to short-dump (st22).

Point has been awarded as my gratitude to you..

Regards,

Niel.