我可以用一个(自写)捕获替换所有捕获并在自编写的异常类型之间切换吗?这样我就可以轻松地在异常中进行调试。
try {
int recordId = recordstore.addRecord(data, 0, data.length);
} catch (RecordStoreFullException e) {
e.printStackTrace();
System.out.println("debuginfo");
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
System.out.println("debuginfo");
} catch (RecordStoreException e) {
e.printStackTrace();
System.out.println("debuginfo");
} catch (NullPointerException e) {
e.printStackTrace();
System.out.println("debuginfo");
} catch (Exception e) {
e.printStackTrace();
System.out.println("debuginfo");
}
答案 0 :(得分:1)
你有什么理由不这样做吗?
try {
int recordId = recordstore.addRecord(data, 0, data.length);
} catch (Exception e) {
// or use a logging framework.
System.err.println("debuginfo");
e.printStackTrace();
}