Application Development and Automation 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: 
Read only

Failed Validation Handling between public caller method and private methods with same class

Former Member
0 Likes
427

Hi

I will like to know the software design to design exception handling within a class. I have a class with both private and public methods. There is a public method which is supposed to do some actions then consolidate all the warnings and errors arose from processing the actions. This is similar to the Function module BAPI_PO_CREATE1, with a return message table.

The implementation of the public method involved calling private methods within the same class for validation.

I want to ask what will be a better way for implementation for the failed validation handling:

  1. Implement the private method to throw exception with custom error message when the validation fails, and the caller will handle the exception class
  2. Return a false boolean/ null indicator when the validation fails, then the caller will check the return indicator. Upon the false return, the caller will place in a custom message into the message table.

Hi

I will like to know the software design to design exception handling within a class. I have a class with both private and public methods. There is a public method which is supposed to do some actions then consolidate all the warnings and errors arose from processing the actions. This is similar to the Function module BAPI_PO_CREATE1, with a return message table.

The implementation of the public method involved calling private methods within the same class for validation.

I want to ask what will be a better way for implementation for the failed validation handling:

  1. Implement the private method to throw exception with custom error message when the validation fails, and the caller will handle the exception class
  2. Return a false boolean/ null indicator when the validation fails, then the caller will check the return indicator. Upon the false return, the caller will place in a custom message into the message table.
1 REPLY 1
Read only

matt
Active Contributor
0 Likes
396

I tend to use things like:

IF is_in_range( ) EQ abap_false.

  RAISE EXCEPTION TYPE zcx_my_exception EXPORTING textid = zcx_my_exception=>out_of_range.

ELSEIF is_valid_in_some_other_way( ) EQ abap_false

  RAISE EXCEPTION TYPE zcx_my_exception EXPORTING textid = zcx_my_exception=>invalid_some_other_way.

ENDIF.

In my view,  the validation methods are making a test. What you do with the result of the test is delegated to the calling method.