Wiki source code of Development-Custom Error Handling
Last modified by Ray Kiddy on 2021/04/22 20:40
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
4.1 | 1 | == Exception Page == |
| |
1.1 | 2 | |
| |
5.1 | 3 | To provide a custom error handler when an exception is thrown, override this WOApplication method: |
| |
1.1 | 4 | |
| |
3.1 | 5 | {{code}} |
| |
1.1 | 6 | |
| |
3.1 | 7 | public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { } |
| |
1.1 | 8 | |
| |
3.1 | 9 | {{/code}} |
| |
1.1 | 10 | |
| 11 | For example: | ||
| 12 | |||
| |
3.1 | 13 | {{code}} |
| |
1.1 | 14 | |
| |
3.1 | 15 | public WOResponse handleException(Exception _exception, WOContext _context) { |
| 16 | Session session = (Session) _context.session(); | ||
| 17 | // do something to notify user of exception, maybe put a message in the session here ... | ||
| 18 | WOResponse response; | ||
| 19 | if (/* you can't handle exception*/) { | ||
| 20 | response = super.handleException(_exception, _context); | ||
| 21 | } | ||
| 22 | else { | ||
| 23 | response = pageWithName(YourExceptionPage.class.getName(), _context).generateResponse(); | ||
| 24 | } | ||
| 25 | return response; | ||
| |
4.1 | 26 | } |
| |
1.1 | 27 | |
| |
3.1 | 28 | {{/code}} |
| |
1.1 | 29 | |
| |
4.1 | 30 | == Session Expired == |
| |
1.1 | 31 | |
| 32 | To provide a custom error handler when an exception is thrown, override the method: | ||
| 33 | |||
| |
3.1 | 34 | {{code}} |
| |
1.1 | 35 | |
| |
3.1 | 36 | public WOResponse handleSessionRestorationErrorInContext(WOContext _context) { |
| |
1.1 | 37 | |
| |
3.1 | 38 | {{/code}} |
| |
1.1 | 39 | |
| 40 | For example: | ||
| 41 | |||
| |
3.1 | 42 | {{code}} |
| |
1.1 | 43 | |
| |
3.1 | 44 | public WOResponse handleSessionRestorationErrorInContext(WOContext _context) { |
| 45 | Session session = (Session) _context.session(); | ||
| 46 | // do something to notify user of exception, maybe put a message in the session here ... | ||
| 47 | WOResponse response = pageWithName(YourErrorPage.class.getName(), _context).generateResponse(); | ||
| 48 | return response; | ||
| 49 | } | ||
| |
1.1 | 50 | |
| |
3.1 | 51 | {{/code}} |
| |
1.1 | 52 | |
| |
4.1 | 53 | == Your Request Produced an Error == |
| |
1.1 | 54 | |
| |
4.1 | 55 | === Chuck Hill === |
| |
1.1 | 56 | |
| 57 | This message started to appear in WO 5.2 when an exception was raised in a DirectAction, but only in deployed applications. Here is what is happening: | ||
| 58 | |||
| 59 | WODisplayExceptionPages | ||
| |
9.1 | 60 | true or false to enable or disable the generation of WOExceptionPages for direct action requests. Default is true in development mode and false in deployment mode. |
| |
1.1 | 61 | |
| |
9.1 | 62 | FromĀ [[https:~~/~~/developer.apple.com/library/archive/documentation/WebObjects/WOAppProperties/Articles/ApplicationProperties.html#~~/~~/apple_ref/doc/uid/TP40005337-SW1>>url:https://developer.apple.com/library/archive/documentation/WebObjects/WOAppProperties/Articles/ApplicationProperties.html#//apple_ref/doc/uid/TP40005337-SW1||shape="rect"]] |
| |
1.1 | 63 | |
| 64 | If the page being returned throws during appendToResponse and the app is deployed, all that is displayed is a blank page with the words "Your request produced an error". | ||
| 65 | |||
| 66 | To avoid this, either add this to the launch agruments: | ||
| 67 | |||
| |
3.1 | 68 | {{noformat}} |
| |
1.1 | 69 | |
| |
3.1 | 70 | -DWODisplayExceptionPages=true |
| |
1.1 | 71 | |
| |
3.1 | 72 | {{/noformat}} |
| |
1.1 | 73 | |
| 74 | Or change the main method in your Application class to look like this: | ||
| 75 | |||
| |
3.1 | 76 | {{code}} |
| |
1.1 | 77 | |
| |
3.1 | 78 | public static void main(String argv[]) { |
| 79 | System.setProperty("WODisplayExceptionPages", "true"); | ||
| 80 | WOApplication.main(argv, Application.class); | ||
| 81 | } | ||
| |
1.1 | 82 | |
| |
3.1 | 83 | {{/code}} |
| |
1.1 | 84 | |
| 85 | This won't work if you put it in the constructor. |