我有以下代码与excpetion处理,这不起作用:
LoadQuestionsDataButton::actionPerformed(ActionEvent)
try
{
questions = ParseXml.parseQuestionsData(questionsDataFile);
// only for broken xml-files!
} catch (java.lang.Exception e)
{
JOptionPane.showMessageDialog(mainWindow, "<html><body>The XML-file seems to be corrupt:<br><br>" +
e.getMessage() +
".</body></html>", "Corrupt XML-file.", JOptionPane.ERROR_MESSAGE);
System.out.println("error-message");
return;
} catch (AssertionError e)
{
JOptionPane.showMessageDialog(mainWindow, "<html>The XML-file seems to be corrupt.<br></html>", "Fehler beim Laden der XML-Datei.", JOptionPane.ERROR_MESSAGE);
return;
}
ArrayList<Question> ParseXml::parseQuestionsData(File)
if(number == "")
{
Exception e;
System.out.println("before exception");
if(firstQuestion)
e = new Exception("The first question does not contain numbering!");
else
e = new Exception("The Question after <" + lastNumber + "> does not contain numbering!");
System.out.println("after exception creation");
throw e;
}
当我用number == ""
加载XML文件时,然后&#34;在异常&#34;之前和#34;创建异常后#34;得到打印,但错误消息对话框和&#34;错误消息&#34;没有!
它还显示堆栈跟踪:
before exception
after exception creation
java.lang.Exception: The first question does not contain numbering!
at com.examquestions.Buttons.ParseXml.parseQuestionsData(ParseXml.java:60)
at com.examquestions.Buttons.LoadQuestionsDataButton.actionPerformed(LoadQuestionsDataButton.java:65)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
[...]
我无法在此处显示更多的堆栈跟踪,因为stackoverflow会抱怨代码太多。
答案 0 :(得分:0)
我在parseQuestionsData(File)
- try-catch
中e.printStackTrace()
catch
包围了{{1}}。
这不行。没记错。