Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.
- Timestamp:
-
02/08/12 16:57:17 (12 years ago)
- Author:
-
wmoore
- Comment:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
-
-
Property
Status
changed from
new
to
accepted
-
v2
|
v4
|
|
45 | 45 | |
46 | 46 | == Custom Error handling == |
47 | | If you want to handle certain exceptions in particular ways, E.g. display a particular message to the user, log particular details etc, |
| 47 | If you want to handle certain exceptions in particular ways |
48 | 48 | you should use appropriate try/except statements. |
49 | | For more info on logging, see [link] |
50 | 49 | |
51 | | This is only advised for trivial errors, where you can give the user a simple message, E.g."No Objects selected, Please try again". |
| 50 | This is only advised for trivial errors, where you can give the user a simple message, E.g."No Objects selected, Please try again", or if the error is well understood and you can recover from the error in a reasonable way. |
52 | 51 | |
53 | | For server errors, it is usually best to allow the exception to be handled by Django since this will provide a lot more info to the user (request details etc) |
| 52 | For 'unexpected' server errors, it is best to allow the exception to be handled by Django since this will provide a lot more info to the user (request details etc) |
54 | 53 | and format html etc (both with Debug True or False). |
55 | | If you still want to handle the exception yourself, you can provide stack trace alongside a message for the user. |
| 54 | |
| 55 | If you still want to handle the exception yourself, you can provide stack trace alongside a message for the user. If the request is ajax, don't return html, since the response text will be displayed in a dialog box for the user (not rendered as html). |
56 | 56 | |
57 | 57 | {{{ |
… |
… |
|
69 | 69 | |
70 | 70 | |
71 | | An alternative is to raise the exception with your custom message, allowing Django to handle it: |
72 | | |
73 | | {{{ |
74 | | |
75 | | except Exception, x: |
76 | | logger.error(traceback.format_exc()) # log the stack trace |
77 | | err_msg = "Something bad happened! \n \n%s" % traceback.format_exc() |
78 | | raise x.__class__(err_msg) |
79 | | }}} |
80 | | |
81 | | However, the stack trace of the Exception will originate from your raise statement, even though the message of the exception |
82 | | contains your original stack trace. |
83 | | |
| 71 | == 404 Errors == |
| 72 | For unknown IDs (Object not found) try to return that message in the 404 message. |
1.3.13-PRO © 2008-2011
Agilo Software all
rights reserved
(this page was served in: 0.12891 sec.)