Browse Source

Exceptions

pull/52/head
Jure Šorn 5 years ago
parent
commit
d598b439b6
2 changed files with 10 additions and 8 deletions
  1. 9
      README.md
  2. 9
      index.html

9
README.md

@ -1372,6 +1372,7 @@ except (<exception>, ...):
except (<exception>, ...) as <name>:
```
* **Also catches subclasses of the exception.**
* **Use `'traceback.print_exc()'` to print the the error message.**
### Raising Exceptions
```python
@ -1390,11 +1391,11 @@ except <exception> as <name>:
### Exception Object
```python
arguments = <name>.args
line_number = <name>.__traceback__.tb_lineno
func_name = <name>.__traceback__.tb_frame.f_code.co_name
exc_type = <name>.__class__
filename = <name>.__traceback__.tb_frame.f_code.co_filename
line = linecache.getline(filename, line_num)
error_msg = traceback.format_exc()
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__)
```
### Built-in Exceptions

9
index.html

@ -1294,6 +1294,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 the error message.</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;()
@ -1306,11 +1307,11 @@ LogicOp = Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-st
</code></pre></div>
<div><h3 id="exceptionobject">Exception Object</h3><pre><code class="python language-python hljs">arguments = &lt;name&gt;.args
line_number = &lt;name&gt;.__traceback__.tb_lineno
func_name = &lt;name&gt;.__traceback__.tb_frame.f_code.co_name
exc_type = &lt;name&gt;.__class__
filename = &lt;name&gt;.__traceback__.tb_frame.f_code.co_filename
line = linecache.getline(filename, line_num)
error_msg = traceback.format_exc()
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__)
</code></pre></div>
<div><h3 id="builtinexceptions">Built-in Exceptions</h3><pre><code class="text language-text">BaseException

Loading…
Cancel
Save