我開發了一個程序,它有一個入口點。 Try catch塊圍繞它。獲取異常對象的錯誤號
try {
Runner runner = new Runner();
// Adhoc code
UIManager.setLookAndFeel(new NimbusLookAndFeel());
runner.setupVariables();
runner.setLookAndFeel();
runner.startSessionFactory();
runner.setupApplicationVariables();
runner.setupDirectories();
// This will be used to test out frames in development mode
if (Runner.isProduction == true) {
execute();
} else {
test();
}
} catch (Exception e) {
SwingHelper.showErrorMessageMainFrame(e.getMessage());
Logger.getRootLogger().error(e);
e.printStackTrace();
}
但是,假設拋出一個空指針異常,消息框是空的,因爲Exception不包含消息。爲此我添加了一個邏輯 -
if(e instanceof NullPointerException){
NullPointerException n =(NullPointerException) e;
SwingHelper.showErrorMessageMainFrame("Unexpected Exception due at ");
}else{
SwingHelper.showErrorMessageMainFrame(e.getMessage());
}
這工作都很好,但我也希望行號被顯示。我怎樣才能完成它。我怎樣才能得到異常的行號?
我要包括到我的圖書館這個代碼。謝謝 – Chan
爲什麼'[2]'?謝謝代理007! –