【发布时间】:2021-08-19 14:56:53
【问题描述】:
我有一个具有完全限定异常名称的字符串变量。如果发生异常,我想检查 catch 块是否是字符串中提到的异常实例。如何解决这个问题
String stringEx = "org.hibernate.StaleStateException";
try {
// program
} catch (Exception ex) {
if (e instanceof stringEx) { //<-- How to convert string to exception class
// do specific process
}
}
【问题讨论】:
-
你已经看过这个stackoverflow.com/questions/27280928/…了吗?