Differences between revisions 6 and 7
Revision 6 as of 2003-09-07 15:23:43
Size: 1125
Editor: dsl254-010-130
Comment: __str__ section no longer necessary, answered question, added "See Also".
Revision 7 as of 2003-09-07 15:24:11
Size: 1014
Editor: dsl254-010-130
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

I (LionKimbro) don't know much about writing exception classes; Here's hoping someone rewrites this better.

Writing Exception Classes

Exception classes are not special, you just derive them from Exception:

   1 class HostNotFound(Exception):
   2     def __init__( self, host ):
   3         self.host = host
   4         Exception.__init__(self, 'Host Not Found exception: missing %s' % host)

You may later write:

   1 try:
   2     raise HostNotFound( "taoriver.net" )
   3 except HostNotFound, X:
   4     # Handle exception.
   5     # "X" is the HostNotFound instance.

See Also

HandlingExceptions, TracebackModule

Questions

  • How do you relay the traceback information? Relay the traceback information? Moving it higher up the call-stack? Could you try to explain your question?

    • When you're logging exceptions, you want access to the traceback information to. After some research, I believe what you use is extract_tb or extract_stack from the traceback module. -- 216.254.10.130 DateTime(2003-09-07T15:23:43Z)

  • What better exception-foo is out there?

WritingExceptionClasses (last edited 2011-05-16 19:13:51 by VPN-18-101-8-113)

Unable to edit the page? See the FrontPage for instructions.