我有一个Swing应用程序,即使我在try
/中都包含了所有内容,block
也没有捕获到异常。
public static void main(String[] args) {
try {
App app = new App();
app.setVisible(true);
} catch (Throwable e) {
System.err.println("never printed");
}
}
我得到的只是这个堆栈跟踪:
Exception in thread "AWT-EventQueue-0"
java.lang.ArrayIndexOutOfBoundsException:
9 >= 9
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:633)
at javax.swing.JTable.getValueAt(JTable.java:2695)
at javax.swing.JTable.prepareRenderer(JTable.java:5712)
at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2075)
at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1977)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1773)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:763)
at javax.swing.JComponent.paint(JComponent.java:1027)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paint(JComponent.java:1036)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:864)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5129)
at javax.swing.BufferStrategyPaintManager.paint
(BufferStrategyPaintManager.java:277)
at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
at javax.swing.JComponent.paint(JComponent.java:1013)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1780)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run
(SystemEventQueueUtilities.java:128)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters
(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter
(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
正如另一位发布者所提到的,您的问题是该异常正在另一个线程(事件调度线程)中引发。几个解决方案:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
// ... do something with exception here ...
}
});
在旁注中,原则上您应该将UI启动代码放在SwingUtilities.invokeLater()中。
问题内容: 发现在Java 1.6(以及从Eclipse)上运行时,吞没了该方法中的异常之后,我试图找到一种捕获这些异常的方法,而不会在我的所有实现中都添加throw / catch 。 该API建议覆盖应对此有所帮助: 导致此future报告一个ExecutionException,并以给定throwable作为其原因,除非已经设置或取消了此Future。计算失败时,run方法在内部调用此方法。
问题内容: 我的JSP页面中有一个复选框,它接受整数值: 如果用户将输入的值更改为一个值,例如: 该页面将引发一个。如何在控制器中捕获并显示有意义的消息? 问题答案: 您可以使用JSTL的 c:catch 标签:
本文向大家介绍如何在Clojurescript中捕获任何JavaScript异常?,包括了如何在Clojurescript中捕获任何JavaScript异常?的使用技巧和注意事项,需要的朋友参考一下 要在Clojurescript中捕获JavaScript异常,请尝试以下代码片段-
本文向大家介绍如何捕获 setTimeout 异常相关面试题,主要包含被问及如何捕获 setTimeout 异常时的应答技巧和注意事项,需要的朋友参考一下 No description provided.
我有一个骡子流,可以抛出异常(无法连接到连接器,组件抛出异常等)。当这种情况发生时,骡子流在异常发生的地方停止。我需要捕获流抛出的任何异常并发送电子邮件通知,指示发生了异常。(尤其是对于像从JMS读取一样异步运行的流)。我应该使用流中的什么元素来捕获任何异常并发送电子邮件? 我试过了: 但这根本就没有开始。我还尝试过: 但这似乎只在流抛出异常时才有效(正常的流功能被改变)。 @David Doss
问题内容: 我们希望在应用程序日志中跟踪这些异常-默认情况下,Java只会将它们输出到控制台。 问题答案: 在EDT中和EDT外,未捕获的异常之间存在区别。 另一个问题有一个解决方案,但是如果您只想咀嚼EDT部分的话…