Message124735
| Author |
ethan.furman |
| Recipients |
draghuram, ethan.furman, ncoghlan, pitrou, poke, steven.daprano |
| Date |
2010年12月27日.21:37:33 |
| SpamBayes Score |
1.7693195e-06 |
| Marked as misclassified |
No |
| Message-id |
<1293485857.86.0.678566183543.issue6210@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I like MRAB's suggestion best:
MRAB wrote:
> Suggestion: an explicit 'raise' in the exception handler excludes the
> context, but if you want to include it then 'raise with'. For example:
>
> # Exclude the context
> try:
> command_dict[command]()
> except KeyError:
> raise CommandError("Unknown command")
>
> # Include the context
> try:
> command_dict[command]()
> except KeyError:
> raise with CommandError("Unknown command")
I think we can even strike off the verbiage "in the exception handler"... that way, raise always does the same thing -- raise KeyError will raise a KeyError, always, not sometimes a KeyError and sometimes a KeyError nested in a WhatEverError. |
|