Project

General

Profile

« Previous | Next » 

Revision 343

exc.py: Added print_ex()

View differences:

lib/exc.py
1 1
# Exception handling
2 2

  
3
def add_msg(e, msg): e.args = (str(e).rstrip()+'\n'+msg,)
3
import sys
4 4

  
5
import strings
6
import util
7

  
8
def add_msg(e, msg): e.args = (strings.ensure_newl(str(e))+msg,)
9

  
5 10
def repl_msg(e, **repls): e.args = (str(e) % repls,)
6 11

  
7 12
class ExceptionWithCause(Exception):
8 13
    def __init__(self, msg, cause=None):
9 14
        Exception.__init__(self, msg)
10 15
        if cause != None: add_msg(self, 'cause: '+str(cause))
16

  
17
def print_ex(e, with_name=True):
18
    msg = strings.ensure_newl(str(e))
19
    if with_name: msg = util.type_name(e)+': '+msg
20
    sys.stderr.write(msg)

Also available in: Unified diff