mybatis mapper学习3-在spring和mybatis中对SQLException多异常或多错误的捕获及代码处理

mybatis3系列文章目录链接


catch (IOException ex) {
     logger.error(ex);
     throw new MyException(ex.getMessage());
catch (SQLException ex) {
     logger.error(ex);
     throw new MyException(ex.getMessage());
}catch (Exception ex) {
     logger.error(ex);
     throw new MyException(ex.getMessage());
}

 

有时候在try   catch中需要区分具体的那个异常,下面一些截图

sqlexception中:

catch(sqlexception ex)

ex.Number=2627  主键重复

ex.Number=-2   timeout

ex.Number=17    sql server 不存在 或者拒绝访问

ex.Number=17142   sql server 暂停

ex.Number=2812  存储过程没有

ex.Number=208 表没有

DuplicateKeyException 是键重复的意思

原文地址:https://www.cnblogs.com/difs/p/9230469.html