Hello! Python by Anthony Briggs

Hello! Python by Anthony Briggs

Author:Anthony Briggs
Language: eng
Format: epub
Publisher: Manning Publications


But handling exceptions on servers doesn’t give you a lot of information about what went wrong. Especially in the case of critical production systems, it’s extremely helpful to know where the error occurred and in what file. You’d like to be able to see tracebacks as if you were running the program locally. Fortunately, there’s a Python module that can help you to print out detailed debugging messages and find out what when wrong: the traceback module.

The traceback module

The traceback module gives you a number of functions for handling exceptions as well as formatting and extracting tracebacks and error messages. The two key ones are print_exc() and format_exc(), which print out a traceback and return a traceback as a string, respectively. You can extract this information from the sys module, via sys.exc_type, sys.exc_value, and sys.exc_traceback, but it’s much more straightforward to use traceback. Let’s extend the error handling in the last section to print out a nice traceback if you get an unknown error, as shown in the following listing.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.