Trace:
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
applications:custom_errorhandling [2019/08/06 13:04] admin |
applications:custom_errorhandling [2019/08/06 22:40] admin |
||
---|---|---|---|
Line 20: | Line 20: | ||
</file> | </file> | ||
- | So, it's very easy to change the default error handling which 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: |
+ | {{: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 work-screens. So, every work-screen should be able to show error messages. To make this possible, we introduce the following interface: | As an example of a custom error handling, 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: | ||
Line 41: | Line 45: | ||
{ | { | ||
labelMain.setText("ErrorArea"); | labelMain.setText("ErrorArea"); | ||
+ | labelMain.setForeground(UIColor.red); | ||
... | ... | ||
Line 91: | 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 107: | Line 112: | ||
We collect all occurred Exceptions in a list - **liErrors** - and show one message at the end, see **showErrorMessages**. \\ | 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 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. | + | In **showErrorMessages**, we iterate through all opened work-screens and check if our 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. |
<file java> | <file java> | ||
Line 118: | Line 123: | ||
public class FirstWorkScreen extends MyCustomWorkScreen | public class FirstWorkScreen extends MyCustomWorkScreen | ||
</file> | </file> | ||
+ | |||
+ | And the result will look like following: | ||
+ | |||
+ | {{:applications:error_screen.jpg?nolink|}} |