2017-02-10 73 views
-6

我遇到以下问题。 我使用XDEV Rapidclipse。 如果发生异常,我想发出notification.show。发生异常时显示错误信息

 EntitiyDAO dao = new EntitiyDAO(); 
    dao.remove(table.getSelectedItem().getBean()); 

我想打电话,但是这却是个例外。 我想现在该程序显示错误消息,每当这个例外过得

感谢

回答

0

你可以导入的JOptionPane import javax.swing.JOptionPane; 和使用一个简单的MessageBox。

try { 
    //code that throws exception 
} catch (Exception ex) { 
    JOptionPane.showMessageDialog (null, ex.getClass().getName() + ": " + ex.getMessage()); 
} 
0

有一些现有的功能,你可以使用,例如用“通知”显示您的消息:

try { 
     // code 
    } 
    catch (final Exception e) { 
     Notification.show("My error message", Type.ERROR_MESSAGE); 
    } 

对于您可以使用模式“窗口”更大的内容的消息。 Rapidclipse提供了一个代码模板。

使用Rapidclipse创建的UI依赖于Vaadin并使用GWT小部件,这些小部件是HTML。也许最好不要混合UI技术。

0

你应该使用Vaadin的通知。

See here for Vaadin Docs

小结:

Notification.show("This is the caption", 
       "This is the description", 
       Notification.Type.HUMANIZED_MESSAGE); 

在你的情况可能是这样的:

try 
{ 
EntitiyDAO dao = new EntitiyDAO(); 
dao.remove(table.getSelectedItem().getBean()); 
} 
catch(Exception e) 
{ 
Notification.show("Something went wrong", 
        e.getMessage(), 
        Notification.Type.ERROR_MESSAGE); 
}