项目总需要提前结束流程, 告知客户端交易流程有误,这时需要直接返回相关的错误信息。然面java项目中太多的底层(非自定义的)异常不想告知客户端(安全性考虑),只需要将自定义的异常告知客户端, 这时需要自定义异常类进行区分。
package com.jqyc.exception; public class MessageException extends RuntimeException { /** * */ private static final long serialVersionUID = 1L; public MessageException(){ super(); } public MessageException(String msg){ super(msg); } }
- 参看:流氓大侠见解 https://www.cnblogs.com/AlanLee/p/6104492.html
- 参看:用法http://blog.csdn.net/u010479322/article/details/51746927
- try ...catch 配合
String rsp = null; if (e instanceof MessageException) { rsp = "0" + "|" + "EEZZ" + "|" + UtilBase64.encode(e.getMessage().getBytes()); } else { rsp = "0" + "|" + "EEZZ" + "|" + UtilBase64.encode("未知错误".getBytes()); LOGGER.error("", e); }