我的问题是如果假设 CalTransactionFactory 未初始化或类不存在。然后我想捕获该异常并抛出异常。所以它应该属于 RuntimeException 或 Exception。下面是代码
try {
calTransaction = CalTransactionFactory.create("PDS_GeoLocationService");
calTransaction.setName("GetLocationByIp");
calEvent=CalEventFactory.create("PersonalizationGeoLocationService");
calEvent.setName("IPAddress");
calEvent.addData("RemoteIP",ipAddress);
calEvent.completed();
calTransaction.setStatus("0");
} catch (RuntimeException re) {
calTransaction.setStatus(re);
getLogger().log(LogLevel.ERROR, "CAL is not initialized" +re.getMessage());
throw re;
}
catch (Exception e) {
getLogger().log(LogLevel.ERROR, "CAL is not initialized" +e.getMessage());
}
最佳答案
java.lang.ClassNotFoundException
是当 JVM 无法通过配置的类加载器找到类文件时抛出的异常。此异常扩展了Exception
。
java.lang.NullPointerException
是当你的变量为 null
并且有东西试图访问它时抛出的异常。它扩展了RuntimeException
,后者扩展了Exception
。
关于java - 如何处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640371/