diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2003-11-05 23:03:00 (GMT) |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2003-11-05 23:03:00 (GMT) |
commit | f607fc5395883ff924c76739e9b0921953568e54 (patch) | |
tree | b48054ff714054bf4390059345215feba4a3703b /Lib/traceback.py | |
parent | 904ed86a777f5e55d370e997f8efb433052ca6e3 (diff) | |
download | cpython-f607fc5395883ff924c76739e9b0921953568e54.zip cpython-f607fc5395883ff924c76739e9b0921953568e54.tar.gz cpython-f607fc5395883ff924c76739e9b0921953568e54.tar.bz2 |
Add traceback.format_exc().
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 4910a37..d99009b 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -6,8 +6,8 @@ import types __all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', - 'format_tb', 'print_exc', 'print_exception', 'print_last', - 'print_stack', 'print_tb', 'tb_lineno'] + 'format_tb', 'print_exc', 'format_exc', 'print_exception', + 'print_last', 'print_stack', 'print_tb', 'tb_lineno'] def _print(file, str='', terminator='\n'): file.write(str+terminator) @@ -211,6 +211,16 @@ def print_exc(limit=None, file=None): finally: etype = value = tb = None + +def format_exc(limit=None): + """Like print_exc() but return a string.""" + try: + etype, value, tb = sys.exc_info() + return ''.join(format_exception(etype, value, tb, limit)) + finally: + etype = value = tb = None + + def print_last(limit=None, file=None): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" |