Wiki source code of Development-Custom Error Handling
Version 8.1 by Pascal Robert on 2010/09/13 00:26
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | == Exception Page == | ||
2 | |||
3 | To provide a custom error handler when an exception is thrown, override this WOApplication method: | ||
4 | |||
5 | {{code}} | ||
6 | |||
7 | public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { } | ||
8 | |||
9 | {{/code}} | ||
10 | |||
11 | For example: | ||
12 | |||
13 | {{code}} | ||
14 | |||
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; | ||
26 | } | ||
27 | |||
28 | {{/code}} | ||
29 | |||
30 | == Session Expired == | ||
31 | |||
32 | To provide a custom error handler when an exception is thrown, override the method: | ||
33 | |||
34 | {{code}} | ||
35 | |||
36 | public WOResponse handleSessionRestorationErrorInContext(WOContext _context) { | ||
37 | |||
38 | {{/code}} | ||
39 | |||
40 | For example: | ||
41 | |||
42 | {{code}} | ||
43 | |||
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 | } | ||
50 | |||
51 | {{/code}} | ||
52 | |||
53 | == Your Request Produced an Error == | ||
54 | |||
55 | === Chuck Hill === | ||
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 | ||
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. | ||
61 | |||
62 | From [[http:~~/~~/developer.apple.com/documentation/WebObjects/WOAppProperties/AppProperties/chapter_1_section_1.html>>url:http://developer.apple.com/documentation/WebObjects/WOAppProperties/AppProperties/chapter_1_section_1.html||shape="rect"]] | ||
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 | |||
68 | {{noformat}} | ||
69 | |||
70 | -DWODisplayExceptionPages=true | ||
71 | |||
72 | {{/noformat}} | ||
73 | |||
74 | Or change the main method in your Application class to look like this: | ||
75 | |||
76 | {{code}} | ||
77 | |||
78 | public static void main(String argv[]) { | ||
79 | System.setProperty("WODisplayExceptionPages", "true"); | ||
80 | WOApplication.main(argv, Application.class); | ||
81 | } | ||
82 | |||
83 | {{/code}} | ||
84 | |||
85 | This won't work if you put it in the constructor. |