Exception handling code handling in spring

I am developing a spring -mvc application.

Below are the steps that I follow to handle exceptions in the code.

  • Wrap an exception in a WrapperException in a catch block (along with some additional details for debugging) and return it back to the caller's method.
  • Finally, handling a WrapperException in the controller.

But the problem with the above approach is that my method contains a lot of code to wrap exceptions and throw it away.

Is this acceptable behavior? or should I change my approach?

Structure My WrapperException.

public class CustomGenericException extends Exception {
    private static final long serialVersionUID = 1L;

    private Exception exception;
    private String errCode; //error code depending on functionality
    private String userMsg; //Extra info like some variable value for debug purpose.
    private String userId;
    private StringBuilder errPath; // Back tracking the path of exception occurrence.

    // getter and setter
}

Thank.

0
source share

All Articles