format_exception¶
-
astropy.utils.misc.
format_exception
(msg, *args, **kwargs)[source] [edit on github]¶ Given an exception message string, uses new-style formatting arguments
{filename}
,{lineno}
,{func}
and/or{text}
to fill in information about the exception that occurred. For example:- try:
- 1/0
- except:
- raise ZeroDivisionError(
- format_except(‘A divide by zero occurred in {filename} at ‘
- ‘line {lineno} of function {func}.’))
Any additional positional or keyword arguments passed to this function are also used to format the message.
Note
This uses
sys.exc_info
to gather up the information needed to fill in the formatting arguments. Python 2.x and 3.x have slightly different behavior regardingsys.exc_info
(the latter will not carry it outside a handled exception), so it’s not wise to use this outside of anexcept
clause - if it is, this will substitute ‘<unkown>’ for the 4 formatting arguments.