10 examples of 'python get exception message' in Python

Every line of 'python get exception message' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
310def collect_exception_python2():
311 """
312 Collect exception from exception sys.exc_info.
313 :return: traceback data
314 """
315
316 traceback_data = six.StringIO()
317 traceback.print_exception(*sys.exc_info(), file=traceback_data)
318 return traceback_data.getvalue()
299def GetErrorDetails():
300 """Returns a string representation of type and message of an exception."""
301 return repr(sys.exc_info()[1])
23def exception_string():
24 """called to extract useful information from an exception"""
25 exc = sys.exc_info()
26 exc_type = _typename(exc[0])
27 exc_message = str(exc[1])
28 exc_contents = "".join(traceback.format_exception(*sys.exc_info()))
29 return "[%s]\n %s" % (exc_type, exc_contents)
331def _extract_msg_from_last_exception():
332 ''' Extract a useful error message from the last thrown exception '''
333 last_exc_type, last_error, last_traceback = sys.exc_info()
334 if isinstance(last_error, exceptions.DXAPIError):
335 # Using the same code path as below would not
336 # produce a useful message when the error contains a
337 # 'details' hash (which would have a last line of
338 # '}')
339 return last_error.error_message()
340 else:
341 return traceback.format_exc().splitlines()[-1].strip()
106def exceptionInfo():
107 (exceptionType, exception, trace) = sys.exc_info()
108 etb = traceback.extract_tb(trace)
109 exceptionType = str(exceptionType.__name__) + ": " + str(exception)
110 exceptInfo = ""
111 for (module, line, function, location) in etb:
112 exceptInfo += " File " + str(module) + ", line " + str(line) + ", in " + str(function) + "\n> " + str(location) + "\n"
113 return ( __getCallContext( withLineNumber = True ), "Exception traceback:\n" + exceptInfo + exceptionType)
30def simple_exception(type, value, traceback):
31 sys.stderr.write("[!] Error!", value, "\n")
32 sys.exit(1)
419def __unicode__(self):
420 entry = self.traceback[-1]
421 loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly())
422 return loc.__unicode__()
16def display_name(exception):
17 prefix = ''
18 # AttributeError has no __module__; RuntimeError has module of
19 # exceptions
20 if hasattr(exception, '__module__') and exception.__module__ != 'exceptions':
21 prefix = exception.__module__ + '.'
22 return prefix + type(exception).__name__
44def exception(*args):
45 import traceback
46 err = []
47 for line in traceback.format_exception(*sys.exc_info()):
48 for line_part in line.strip().split('\n'):
49 err.append('[exc] ' + line_part)
50 if len(args):
51 try:
52 err.insert(0, '[exc] ' + (str(args[0]) % args[1:]))
53 except TypeError:
54 err.insert(0,'[exc] ' + repr(args))
55 for line in err:
56 error(line)
244def format_exc(self):
245 """
246 Format the latest exception's traceback.
247 """
248 return self._format_tb_string_with_locals(*sys.exc_info())

Related snippets