1270
Comment: Updated example to use super()
|
2248
hm, doesn't seem to work (Py2.3, at least)
|
Deletions are marked like this. | Additions are marked like this. |
Line 40: | Line 40: |
* The new text involving {{{super}}} doesn't seem to work for me. Using Python 2.3: {{{ #!python class LocalNamesSyntaxError(Exception): def __init__(self, msg): self.msg=msg super(LocalNamesSyntaxError, self)('Local Names v1.1 Syntax Error: %s' % msg) }}} {{{ Traceback (most recent call last): File "parser.py", line 92, in ? pprint.pprint(parse_text(test_string)) File "parser.py", line 69, in parse_text cursor=parse_record_type(cursor,line,results) File "parser.py", line 43, in parse_record_type raise LocalNamesSyntaxError("unrecognized v1.1 record type- require LN, NS, X, or PATTERN") File "parser.py", line 17, in __init__ super(LocalNamesSyntaxError, self)('Local Names v1.1 Syntax Error: %s' % msg) TypeError: super() argument 1 must be type, not classobj }}} Is this a Python2.4 v. Python2.3 thing? Or is there a simple error in my code? -- LionKimbro [[DateTime(2004-12-28T21:00:40Z)]] |
Writing Exception Classes
Exception classes are not special, you just derive them from Exception:
You may later write:
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. -- LionKimbro DateTime(2003-09-07T15:23:43Z)
Look at cgitb for how to do detailed TB introspection, and as an example of why mixing logic and (HTML) layout is a very bad thing.
- What better exception-foo is out there?
AlexMartelli's "Dos and Don'ts".
The new text involving super doesn't seem to work for me.
Using Python 2.3:
Traceback (most recent call last): File "parser.py", line 92, in ? pprint.pprint(parse_text(test_string)) File "parser.py", line 69, in parse_text cursor=parse_record_type(cursor,line,results) File "parser.py", line 43, in parse_record_type raise LocalNamesSyntaxError("unrecognized v1.1 record type- require LN, NS, X, or PATTERN") File "parser.py", line 17, in __init__ super(LocalNamesSyntaxError, self)('Local Names v1.1 Syntax Error: %s' % msg) TypeError: super() argument 1 must be type, not classobj
Is this a Python2.4 v. Python2.3 thing? Or is there a simple error in my code? -- LionKimbro DateTime(2004-12-28T21:00:40Z)