10 examples of 'get message from exception python' in Python

Every line of 'get message from exception python' 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
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()
36def get_message(exception):
37 message = None
38
39 if hasattr(exception, 'message'):
40 message = exception.message
41 elif hasattr(exception, '__str__'):
42 message = e.__str__()
43 else:
44 message = "Something went wrong while syncing"
45 return message
299def GetErrorDetails():
300 """Returns a string representation of type and message of an exception."""
301 return repr(sys.exc_info()[1])
350def _safe_message(exception):
351 msg = exception.message
352 if isinstance(msg, str) or isinstance(msg, unicode):
353 return msg
354 try:
355 return str(msg)
356 except:
357 return ""
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()
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)
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)
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__
85def _message(self, env):
86 """Override to modify message expression."""
87 if env.SHOW_MESSAGE is False:
88 return ''
89 msg = self.message
90 if not self._show_message(msg):
91 return ''
92 return msg
14def _get_message(self):
15 return self._message

Related snippets