def format_exc(exc=None):
    """Return exc (or sys.exc_info if None), formatted."""
    try:
        if exc is None:
            exc = _exc_info()
        if exc == (None, None, None):
            return ''
        import traceback

        return ''.join(traceback.format_exception(*exc))
    finally:
        del exc
Return exc (or sys.exc_info if None), formatted.
cherrypy/_cperror.py