Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
applications:custom_errorhandling [2019/08/06 13:00]
admin
applications:custom_errorhandling [2020/07/08 13:14] (current)
cduncan articles
Line 1: Line 1:
 ~~NOTRANS~~ ~~NOTRANS~~
-~~Title: Custom ​error handling~~+~~Title: Custom ​Error Handling~~
  
-The application ​itself ​implements the IExceptionListener interface and registers itself as listener:+The application ​(ProjX) ​implements the **IExceptionListener** interface and registers itself as listener:
  
 <file java> <file java>
Line 13: Line 13:
 </​file>​ </​file>​
  
-All Exceptions ​will be handled in one method: ​+All exceptions ​will be handled in the listener ​method: ​
  
 <file java> <file java>
Line 20: Line 20:
 </​file>​ </​file>​
  
-So, it's very easy to change the default error handling. The default error handling ​shows a popup dialog ​with the error message and some details (stack trace). ​+So, it's very easy to change the default error handling ​which shows a popup dialog
  
-As example, we'll show the exceptions directly in the work-screens. So, every work-screen ​should be able to show error messages. To make this possible, we introduce the following interface:+{{:​applications:​error_dialog.png?​nolink|}} 
 + 
 +with the error message and some details (stack trace). \\  
 +\\  
 +As an example ​of a custom error handling, we'll show the exceptions directly in the workscreens. So, every workscreen ​should be able to show error messages. To make this possible, we introduce the following interface:
  
 <file java> <file java>
Line 30: Line 34:
 } }
 </​file>​ </​file>​
-and all our work-screens ​should implement ​it like this example:+and all our workscreens ​should implement ​the interface, e.g.:
  
 <file java> <file java>
Line 41: Line 45:
     {     {
         labelMain.setText("​ErrorArea"​);​         labelMain.setText("​ErrorArea"​);​
 +        labelMain.setForeground(UIColor.red);​
  
         ...         ...
Line 62: Line 67:
 </​file>​ </​file>​
  
-So, our work-screen ​example contains a new label in the SOUTH area (the bottom of the screen). The label will be hidden initially in **onLoad()**. Our screen is now ready to show error messages, but our application must be changed. To do this, we need a [[vaadin:​customize_application|custom application]].+So, our workscreen ​example contains a new label in the SOUTH area (the bottom of the screen). The label will be hidden initially in **onLoad()**. ​\\ 
 +Our screen is now ready to show error messages, but our application must be changed. To do this, we need a [[vaadin:​customize_application|custom application]].
  
-Our application contains following code:+Our application contains ​the following code:
  
 <file java MyCustomApplication.java>​ <file java MyCustomApplication.java>​
Line 90: Line 96:
     public void showErrorMessage()     public void showErrorMessage()
     {     {
-        String message = liErrors.get(0).getMessage();​+        String message = ExceptionUtil.getRootCause(liErrors.get(0)).getMessage();​
         ​         ​
         for (IWorkScreen screen : getWorkScreens())         for (IWorkScreen screen : getWorkScreens())
Line 104: Line 110:
 } }
 </​file>​ </​file>​
-We collect all occurred ​Exceptions ​and show one message at the end. We iterate through all opened ​work-screens ​and check if the interface is implemented. In our example, every work-screen ​has to implement the interface IErrorHandler. A better solution would be a custom ​work-screen ​base class, e.g. +We collect all occurred ​exceptions in a list - **liErrors** - and show one message at the end, see **showErrorMessages**\\ 
 +\\  
 +In **showErrorMessages**,​ we iterate through all opened ​workscreens ​and check if our interface is implemented. In our example, every workscreen ​has to implement the interface ​**IErrorHandler**. A better solution would be a custom ​workscreen ​base class, e.g. 
  
 <file java> <file java>
Line 111: Line 119:
 } }
 </​file>​ </​file>​
-and all our work-screens ​should extend this base screen:+and all our workscreens ​should extend this base screen:
 <file java> <file java>
 public class FirstWorkScreen extends MyCustomWorkScreen public class FirstWorkScreen extends MyCustomWorkScreen
 </​file>​ </​file>​
 +
 +And the result will look like the following:
 +
 +{{:​applications:​error_screen.jpg?​nolink|}}
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information