就可以捕獲錯誤即
try {
numericDefinition = new net.sf.cb2xml.def.BasicNumericDefinition(
binName, binarySizes, SynchronizeAt, usePositive, floatSynchronize, doubleSynchronize
);
} catch (NoClassDefFoundError e) {
System.out.println("Class Not Found: " + e.getMessage());
}
你必須非常小心你的編碼雖然,這是很容易得到的NoClassDefFoundError在類初始化時引發,而不是進入到試。 。catch塊。
的的NoClassDefFoundError將拋出的第一次類refereneced這可能是什麼時候可以當一個類使用它使用它使用一類...它使用一個類引用的類,它的類的類不存在。
由於導入,在類初始化時,以下可能會因NoClassDefFoundError而失敗。
import net.sf.cb2xml.def.BasicNumericDefinition; // could cause the NoClassDefFoundError
...........
try {
numericDefinition = new BasicNumericDefinition(
binName, binarySizes, SynchronizeAt, usePositive, floatSynchronize, doubleSynchronize
);
} catch (NoClassDefFoundError e) {
System.out.println("Class Not Found: " + e.getMessage());
}
http://www.hiteshagrawal.com/java/sending-email-using-apache-log4j – oers
我看着log4j的一點,但是從我的理解,我不認爲這工作。 NoClassDefFoundError無法在程序內部被捕獲,因爲它強制立即退出。 – Numeron
在你的靜態主要方法中,你可以包含一個try ... catch(Throwable)...這將能夠處理noclassdeferror – oers