Last modified by Ray Kiddy on 2021/04/22 20:40

From version 7.1
edited by Pascal Robert
on 2010/09/13 00:26
Change comment: There is no comment for this version
To version 1.1
edited by smmccraw
on 2007/07/08 09:45
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Development-Custom Error Handling
1 +Programming__WebObjects-Web Applications-Development-Custom Error Handling
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.probert
1 +XWiki.smmccraw
Content
... ... @@ -1,85 +1,88 @@
1 -== Exception Page ==
1 +== Exception Page ==
2 2  
3 -To provide a custom error handler when an exception is thrown, override this WOApplication method:
3 +To provide a custom error handler when an exception is thrown, override the method:
4 4  
5 -{{code}}
5 +{{panel}}
6 6  
7 -public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { }
7 + public WOResponse handleException (java.lang.Exception anException, WOContext aContext) { }
8 8  
9 -{{/code}}
9 +{{/panel}}
10 10  
11 11  For example:
12 12  
13 -{{code}}
13 +{{panel}}
14 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 -}
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 27  
28 -{{/code}}
28 +{{/panel}}
29 29  
30 -== Session Expired ==
30 +== Session Expired ==
31 31  
32 32  To provide a custom error handler when an exception is thrown, override the method:
33 33  
34 -{{code}}
34 +{{panel}}
35 35  
36 -public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
36 + public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
37 37  
38 -{{/code}}
38 +{{/panel}}
39 39  
40 40  For example:
41 41  
42 -{{code}}
42 +{{panel}}
43 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 -}
44 +
45 + public WOResponse handleSessionRestorationErrorInContext(WOContext _context) {
46 + Session session = (Session) _context.session();
47 + // do something to notify user of exception, maybe put a message in the session here ...
48 + WOResponse response = pageWithName(YourErrorPage.class.getName(), _context).generateResponse();
49 + return response;
50 + }
50 50  
51 -{{/code}}
52 +{{/panel}}
52 52  
53 -== Your Request Produced an Error ==
54 +== Your Request Produced an Error ==
54 54  
55 -=== Chuck Hill ===
56 +=== Chuck Hill ===
56 56  
57 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 58  
59 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 +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 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 +From http:~/~/developer.apple.com/documentation/WebObjects/WOAppProperties/AppProperties/chapter_1_section_1.html
63 63  
64 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 65  
66 66  To avoid this, either add this to the launch agruments:
67 67  
68 -{{noformat}}
69 +{{panel}}
69 69  
70 --DWODisplayExceptionPages=true
71 + -DWODisplayExceptionPages=true
71 71  
72 -{{/noformat}}
73 +{{/panel}}
73 73  
74 74  Or change the main method in your Application class to look like this:
75 75  
76 -{{code}}
77 +{{panel}}
77 77  
78 -public static void main(String argv[]) {
79 - System.setProperty("WODisplayExceptionPages", "true");
80 - WOApplication.main(argv, Application.class);
81 -}
79 + public static void main(String argv[]) {
80 + System.setProperty("WODisplayExceptionPages", "true");
81 + WOApplication.main(argv, Application.class);
82 + }
82 82  
83 -{{/code}}
84 +{{/panel}}
84 84  
85 85  This won't work if you put it in the constructor.
87 +
88 +Category:WebObjects