mybatis RuntimeSQLException 与 SqlSessionException

mybatis RuntimeSQLException vs SqlSessionException

我正在尝试将 ibatis 代码转换为 mybatis。我的 ibatis 代码就像

try {
    sqlMap.insert("insertinfo", insertData);
}
catch (SQLException sqle) {
    Logger.error("error occurred while inserting",sqle);
}

现在在mybatis上,

try {
        session.insert("insertinfo", insertData);
    }
    // what exception to catch ?? RuntimeSQLException or SqlSessionException
     catch ( ?? sqle) {
        Logger.error("error occurred while inserting",sqle);
    }

我尝试同时使用 RuntimeSQLExceptionSqlSessionException,两者都工作正常。但是我不知道该用哪一个。

我在搜索 mybatis 的类似问题时发现了这个 post。 This 是我最初的问题。根据评论和我自己的研究,我试图给出答案。

SQLException是checked exception,Mybatis只支持RuntimeException所以mybatis不能使用SQLException

SqlSessionException是Mybatis使用的RuntimeException。 refer this

RunTimeSQLException 基本上是 SQLException 的包装器,以促进实际 SQLException 的传递,即由 JDBC 驱动程序抛出的异常,不同于其他与 Mybatis 操作相关的异常 source