Python's Traceback__python

Source: Internet
Author: User

Python exception module Traceback usage examples

Traceback.print_exc () #把返回信息输出到控制台

fp = Stringio.stringio () #创建内存文件对象
Traceback.print_exc (FILE=FP) #把返回信息写到文件中去
message = Fp.getvalue () #获得信息

Figuring out Python Traceback

In fact, the TRACEBACK.PRINT_EXC () function is simply a shorthand form of the traceback.print_exception () function, and the data they obtain from the exception are obtained by the Sys.exc_info () function.

Traceback module uses Traceback object

Print_exception (etype, Value, tb[, limit[, file])

Print_exc ([limit[, file]]) is a shorthand for print_exception print_exception (Sys.exc_type, Sys.exc_value, Sys.exc_traceback, limit , file) (it uses Sys.exc_info ())

FORMAT_EXC ([limit]) (much like print_exc (limit)) directly returns the string, does not output to the stream, does not have to use the above Stringio to get the string, in 2.4 of the newly added

Limit parameters, which limit the number of error layers returned, that is, when function B is called, an exception occurs in function B, and if limit=1, only the error in display function A is returned, and if limit is set, all returns.

The file parameter, specifying the output to the document.

Other methods See official documentation Traceback-print or retrieve a stack traceback

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.