1

I am developing spring-mvc application.

Below steps I am doing to handle exception in the code.

  1. Wrapping the exception in WrapperException in the catch block (along with some extra details for debugging) and throwing it back to the caller method.
  2. Finally handling WrapperException in controller.

But the problem with above approach is my method contains large amount of code for exception wrapping and throwing it back.

Is it the accepted behavior? or should I change my approach?

My WrapperException structure.

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
}

Thanks.

Naman Gala
  • 4,670
  • 1
  • 21
  • 55

0 Answers0