Browse Source

Exceptions

pull/79/head
Jure Šorn 4 years ago
parent
commit
daaa45b3ab
2 changed files with 4 additions and 2 deletions
  1. 3
      README.md
  2. 3
      index.html

3
README.md

@ -1374,6 +1374,7 @@ except (<exception>, [...]) as <name>:
```
* **Also catches subclasses of the exception.**
* **Use `'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
```python
@ -1396,7 +1397,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

3
index.html

@ -1311,6 +1311,7 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
<ul>
<li><strong>Also catches subclasses of the exception.</strong></li>
<li><strong>Use <code class="python hljs"><span class="hljs-string">'traceback.print_exc()'</span></code> to print the error message to stderr.</strong></li>
<li><strong>Use <code class="python hljs"><span class="hljs-string">'print(&lt;name&gt;, file=sys.stderr)'</span></code> to print just the cause of the exception.</strong></li>
</ul>
<div><h3 id="raisingexceptions">Raising Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> &lt;exception&gt;
<span class="hljs-keyword">raise</span> &lt;exception&gt;()
@ -1327,7 +1328,7 @@ exc_type = &lt;name&gt;.__class__
filename = &lt;name&gt;.__traceback__.tb_frame.f_code.co_filename
func_name = &lt;name&gt;.__traceback__.tb_frame.f_code.co_name
line = linecache.getline(filename, &lt;name&gt;.__traceback__.tb_lineno)
error_msg = traceback.format_exception(exc_type, &lt;name&gt;, &lt;name&gt;.__traceback__)
error_msg = <span class="hljs-string">''</span>.join(traceback.format_exception(exc_type, &lt;name&gt;, &lt;name&gt;.__traceback__))
</code></pre></div>
<div><h3 id="builtinexceptions">Built-in Exceptions</h3><pre><code class="text language-text">BaseException

Loading…
Cancel
Save