From daaa45b3ab724f7cdc6345c6096edede295bba1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 21 Oct 2020 18:27:52 +0200 Subject: [PATCH] Exceptions --- README.md | 3 ++- index.html | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a85c2a..9fa21f3 100644 --- a/README.md +++ b/README.md @@ -1374,6 +1374,7 @@ except (, [...]) as : ``` * **Also catches subclasses of the exception.** * **Use `'traceback.print_exc()'` to print the error message to stderr.** +* **Use `'print(, file=sys.stderr)'` to print just the cause of the exception.** ### Raising Exceptions ```python @@ -1396,7 +1397,7 @@ exc_type = .__class__ filename = .__traceback__.tb_frame.f_code.co_filename func_name = .__traceback__.tb_frame.f_code.co_name line = linecache.getline(filename, .__traceback__.tb_lineno) -error_msg = traceback.format_exception(exc_type, , .__traceback__) +error_msg = ''.join(traceback.format_exception(exc_type, , .__traceback__)) ``` ### Built-in Exceptions diff --git a/index.html b/index.html index af73af8..fe559b4 100644 --- a/index.html +++ b/index.html @@ -1311,6 +1311,7 @@ LogicOp = Enum('LogicOp', {'traceback.print_exc()' to print the error message to stderr. +
  • Use 'print(<name>, file=sys.stderr)' to print just the cause of the exception.
  • Raising Exceptions

    raise <exception>
     raise <exception>()
    @@ -1327,7 +1328,7 @@ exc_type  = <name>.__class__
     filename  = <name>.__traceback__.tb_frame.f_code.co_filename
     func_name = <name>.__traceback__.tb_frame.f_code.co_name
     line      = linecache.getline(filename, <name>.__traceback__.tb_lineno)
    -error_msg = traceback.format_exception(exc_type, <name>, <name>.__traceback__)
    +error_msg = ''.join(traceback.format_exception(exc_type, <name>, <name>.__traceback__))
     

    Built-in Exceptions

    BaseException