记录一个异常

场景:新增一个数据。长度超过数据库设置的长度,service中捕获了异常,但是没有显示数据库的异常。

这种:Cause: java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)

愿景:把这个异常信息放到页面,方便定位问题。

方案:dao层insert方法声明异常:throws VmsBusinessException

 1     /**新增合同车信息表**/
 2     @Override
 3     public void insertVmsContractVehicle(VmsContractVehicle entity) throws VmsBusinessException{
 4         try {
 5             super.insert("insertVmsContractVehicle", entity);
 6         } catch (Exception e) {
 7             super.getLogger().error(e.getMessage(), e);
 8             throw new VmsBusinessException("合同车信息表增加出现异常"+e.getMessage());
 9         }
10         
11     }
View Code

 

 1 package com.ycg.rosefinch.vms.manager.service.common;
 2 
 3 import com.ycg.rdc.framework.application.exception.BusinessException;
 4 
 5 public class VmsBusinessException extends BusinessException {
 6     private static final long serialVersionUID = -1054869492237073561L;
 7 
 8     /**
 9      * 异常code
10      */
11     protected String errCode;
12 
13     /**
14      * 异常信息
15      */
16     private String natvieMsg;
17 
18     /**
19      * 异常 arguments
20      */
21     private Object[] arguments;
22     public VmsBusinessException() {
23         super();
24     }
25 
26     public VmsBusinessException(String msg) {
27         super(msg);
28     }
29 
30     public VmsBusinessException(String msg, Throwable cause) {
31         super(msg, cause);
32     }
33 
34     public VmsBusinessException(String code, String msg) {
35         super(msg);
36         this.errCode = code;
37     }
38 
39     public VmsBusinessException(String code, String msg, Throwable cause) {
40         super(msg, cause);
41         this.errCode = code;
42     }
43 
44     public VmsBusinessException(String code, String msg, String natvieMsg) {
45         super(msg);
46         this.errCode = code;
47         this.natvieMsg = natvieMsg;
48     }
49 
50     public VmsBusinessException(String code, String msg,String natvieMsg, Throwable cause) {
51         super(msg, cause);
52         this.errCode = code;
53         this.natvieMsg = natvieMsg;
54     }
55 
56     public VmsBusinessException(String code,Object... args) {
57         super();
58         this.errCode = code;
59         this.arguments = args;
60     }
61 
62     public VmsBusinessException(String code,String msg, Object... args) {
63         super(msg);
64         this.errCode = code;
65         this.arguments = args;
66     }
67 
68     @Override
69     public void setErrorArguments(Object... args) {
70         this.arguments = args;
71     }
72 
73     @Override
74     public Object[] getErrorArguments() {
75         return this.arguments;
76     }
77 
78     @Override
79     public String getErrorCode() {
80         return this.errCode;
81     }
82 
83     @Override
84     public String getNativeMessage() {
85         return natvieMsg;
86     }
87 }
View Code
获取成功:
1 {
2     "StatusCode": "Lx011-00001-0000021",
3     "Data": null,
4     "ErrorMessage": "合同车信息表增加出现异常\r\n### Error updating database.  Cause: java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n\r\n### The error may involve com.ycg.rosefinch.vms.manager.service.entity.VmsContractVehicle.VmsContractVehicleQueryEntity\r\n### The error occurred while setting parameters\r\n### SQL: INSERT INTO T_VMS_CONTRACT_VEHICLE   (ID,VEHICLE_ID,VEHICLE_NO        ,DRIVER_NAME            ,DRIVER_PHONE            ,SUPPLIER_NAME            ,SUPPLIER_CODE            ,CONTRACT_BEGIN_DATE            ,CONTRACT_END_DATE            ,ONLINE_DATE       )   VALUES   (   ?   ,?   ,?        ,?            ,?            ,?            ,?            ,?            ,?            ,?       )\r\n### Cause: java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n\n; uncategorized SQLException for SQL []; SQL state [72000]; error code [12899]; ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n; nested exception is java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n",
5     "ExptMsgDetail": "车辆信息添加异常!合同车信息表增加出现异常\r\n### Error updating database.  Cause: java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n\r\n### The error may involve com.ycg.rosefinch.vms.manager.service.entity.VmsContractVehicle.VmsContractVehicleQueryEntity\r\n### The error occurred while setting parameters\r\n### SQL: INSERT INTO T_VMS_CONTRACT_VEHICLE   (ID,VEHICLE_ID,VEHICLE_NO        ,DRIVER_NAME            ,DRIVER_PHONE            ,SUPPLIER_NAME            ,SUPPLIER_CODE            ,CONTRACT_BEGIN_DATE            ,CONTRACT_END_DATE            ,ONLINE_DATE       )   VALUES   (   ?   ,?   ,?        ,?            ,?            ,?            ,?            ,?            ,?            ,?       )\r\n### Cause: java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n\n; uncategorized SQLException for SQL []; SQL state [72000]; error code [12899]; ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n; nested exception is java.sql.SQLException: ORA-12899: 列 \"OP\".\"T_VMS_CONTRACT_VEHICLE\".\"DRIVER_NAME\" 的值太大 (实际值: 154, 最大值: 100)\n"
6 }
View Code

 

转载于:https://www.cnblogs.com/acme6/p/8986679.html

你可能感兴趣的:(记录一个异常)