zoukankan      html  css  js  c++  java
  • Exception自定义处理模型

    伪代码:


    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);
        }
    }
    


  • 相关阅读:
    将本地文件夹添加到Git仓库
    flex调用Webservice(一)
    经典的sql
    打印相关
    reporting services订阅
    关于TabIndex
    试题(一)
    试试用手机
    2010.07.13_19:30
    基础知识
  • 原文地址:https://www.cnblogs.com/silyvin/p/9106719.html
Copyright © 2011-2022 走看看