我正在尝试在 actionlistener 的内部类中使用 try/catch 语句,但即使我故意触发它们,它也不会捕获异常。这是代码摘录:
btnPerformCalculation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
double runtime = Math.abs(Double.parseDouble(txtRunTime.getText()));
double downtime = Math.abs(Double.parseDouble(txtDownTime.getText()));
double blockedtime = Math.abs(Double.parseDouble(txtBlockedTime.getText()));
double lineefficiency = 100 * runtime / (runtime + downtime + blockedtime);
try {
txtEfficiencyAnswer.setText(String.format("%.2f", lineefficiency));
} catch (Exception e) {
JOptionPane.showMessageDialog(frame, "Error:" + e.getMessage());
txtRunTime.setText("0");
txtDownTime.setText("0");
txtBlockedTime.setText("0");
}
}
});