CRITICAL
Rule Definition
An empty catch block defeats the purpose of exceptions. When an exception occurs, nothing happens and the program fails for unknown reason. The applications can be in an unknown state that will affect subsequent processing. Since the reason of the issue (the type of the exception and potential emmbedded message) are ignored, it will require more time to fix the issue.
Remediation
The exception must be handled properly accordingly to its type in a catch block.
Violation Code Sample
TRY.
RESULT = 1 / NUMBER.
write: / 'Result of division:', RESULT.
RESULT = SQRT( NUMBER ).
write: / 'Result of square root:', RESULT.
CATCH CX_SY_ZERODIVIDE into OREF.
* This CATCH block does not contain statements
* and can be considered as not existing...
* TEXT = OREF->GET_TEXT( ).
ENDTRY.
Fixed Code Sample
TRY.
RESULT = 1 / NUMBER.
write: / 'Result of division:', RESULT.
RESULT = SQRT( NUMBER ).
write: / 'Result of square root:', RESULT.
CATCH CX_SY_ZERODIVIDE into OREF.
TEXT = OREF->GET_TEXT( ).
cleanup.
clear RESULT.
ENDTRY.
Reference
An insider's guide to writing robust, understandable, maintainable, state-of-the-art ABAP programs - Part 3
Andreas Blumenthal - Horst Keller
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.