silyvin

伪代码:


Res methodB() throws Exception {

    Res res = new Res();

    ......

    if(res.getResult == false)

        throws MyException("MyError:"+res.getMsg);



    return res;

}

void methodA() {

    try{

        Res res = mothodB();

        log.info(res.toString());

    } catch(MyException e) {

        log.error(e.getMessage());      // 可以精确定位问题代码行数,所以仅打印msg
        // log.error(e.getMessage(), m);    // 可以打印堆栈,但无意义

    } catch(Exception e) {

        log.error(e.getMessage(), m);     // 其它运行期未知异常,打印完整含堆栈信息,也可以再向上抛出
    }

}



public class MyException extends Exception
{

    private static final long serialVersionUID = 1364102728393959890L;

    public MyException() {
        super();
    }

    public MyException(String message, Throwable cause) {
        super(message, cause);
    }

    public MyException(String message) {
        super(message);
    }

    public MyException(Throwable cause) {
        super(cause);
    }
}


分类:

技术点:

相关文章:

  • 2021-06-09
  • 2018-09-09
  • 2021-08-03
  • 2021-11-25
  • 2021-06-22
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
猜你喜欢
  • 2022-02-21
  • 2021-12-18
  • 2021-08-09
  • 2022-01-15
  • 2021-11-28
  • 2022-01-10
  • 2022-02-01
相关资源
相似解决方案