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: 

Shortest form for "IF condition THEN throw exception" in one line

Sandra_Rossi
Active Contributor
0 Kudos

Hi experts,

I've got a silly question. Like everybody, I often use these lines of code:

IF sy-subrc <> 0.

  RAISE EXCEPTION TYPE zcx_error.

ENDIF.

I'd like to write it on one line, so that the code is more concise (*), but the pretty printer automatically redistributes it on 3 lines, on my 7.40 system.

(*) I want the code for exception handling to be very thin when I read the code, so that to concentrate immediately on the important parts of the code.

I tried to use the new constructor operator COND with THROW word, but it's a little ugly.

DATA(i) = COND i( WHEN sy-subrc <> 0 THEN THROW zcx_error( ) ).

Do you have any idea how I can do it nicely?

Thanks a lot.

Sandra

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Sorry, my fault. The pretty printer doesn't distribute it automatically on 3 lines !

1 REPLY 1

Sandra_Rossi
Active Contributor
0 Kudos

Sorry, my fault. The pretty printer doesn't distribute it automatically on 3 lines !