Exception handling code review in spring

时光毁灭记忆、已成空白 提交于 2019-12-12 02:02:48

问题


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.

来源:https://stackoverflow.com/questions/27633772/exception-handling-code-review-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!