エラーをキャッチすることができます
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 がスローされて、try .. catch ブロックに進まないのは簡単です。
NoClassDefFoundErrorは、クラスが初めて参照されるときにスローされます。これは、存在しないクラスを参照するクラスを使用するクラスを使用するクラスをクラスが使用する場合に発生する可能性があります。
以下は、インポートが原因で、クラスの初期化時に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());
}