Browse Source

Exceptions

pull/52/head
Jure Šorn 4 years ago
parent
commit
a97d71ba8d
2 changed files with 14 additions and 14 deletions
  1. 16
      README.md
  2. 12
      index.html

16
README.md

@ -1396,7 +1396,7 @@ line = linecache.getline(filename, line_num)
error_msg = traceback.format_exc() error_msg = traceback.format_exc()
``` ```
### Common Built-in Exceptions
### Built-in Exceptions
```text ```text
BaseException BaseException
+-- SystemExit # Raised by the sys.exit() function. +-- SystemExit # Raised by the sys.exit() function.
@ -1420,13 +1420,6 @@ BaseException
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails. +-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
``` ```
#### Useful built-in exceptions:
```python
raise TypeError('Argument is of wrong type!')
raise ValueError('Argument is of right type but inappropriate value!')
raise RuntimeError('None of above!')
```
#### Collections and their exceptions: #### Collections and their exceptions:
```text ```text
+-----------+------------+------------+------------+ +-----------+------------+------------+------------+
@ -1439,6 +1432,13 @@ raise RuntimeError('None of above!')
+-----------+------------+------------+------------+ +-----------+------------+------------+------------+
``` ```
#### Useful built-in exceptions:
```python
raise TypeError('Argument is of wrong type!')
raise ValueError('Argument is of right type but inappropriate value!')
raise RuntimeError('None of above!')
```
### User-defined Exceptions ### User-defined Exceptions
```python ```python
class MyError(Exception): class MyError(Exception):

12
index.html

@ -1310,7 +1310,7 @@ line = linecache.getline(filename, line_num)
error_msg = traceback.format_exc() error_msg = traceback.format_exc()
</code></pre></div> </code></pre></div>
<div><h3 id="commonbuiltinexceptions">Common Built-in Exceptions</h3><pre><code class="text language-text">BaseException
<div><h3 id="builtinexceptions">Built-in Exceptions</h3><pre><code class="text language-text">BaseException
+-- SystemExit # Raised by the sys.exit() function. +-- SystemExit # Raised by the sys.exit() function.
+-- KeyboardInterrupt # Raised when the user hits the interrupt key (ctrl-c). +-- KeyboardInterrupt # Raised when the user hits the interrupt key (ctrl-c).
+-- Exception # User-defined exceptions should be derived from this class. +-- Exception # User-defined exceptions should be derived from this class.
@ -1332,11 +1332,6 @@ error_msg = traceback.format_exc()
+-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails. +-- UnicodeError # Raised when encoding/decoding strings from/to bytes fails.
</code></pre></div> </code></pre></div>
<div><h4 id="usefulbuiltinexceptions">Useful built-in exceptions:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> TypeError(<span class="hljs-string">'Argument is of wrong type!'</span>)
<span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">'Argument is of right type but inappropriate value!'</span>)
<span class="hljs-keyword">raise</span> RuntimeError(<span class="hljs-string">'None of above!'</span>)
</code></pre></div>
<div><h4 id="collectionsandtheirexceptions">Collections and their exceptions:</h4><pre><code class="text language-text">+-----------+------------+------------+------------+ <div><h4 id="collectionsandtheirexceptions">Collections and their exceptions:</h4><pre><code class="text language-text">+-----------+------------+------------+------------+
| | list | dict | set | | | list | dict | set |
+-----------+------------+------------+------------+ +-----------+------------+------------+------------+
@ -1347,6 +1342,11 @@ error_msg = traceback.format_exc()
+-----------+------------+------------+------------+ +-----------+------------+------------+------------+
</code></pre></div> </code></pre></div>
<div><h4 id="usefulbuiltinexceptions">Useful built-in exceptions:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> TypeError(<span class="hljs-string">'Argument is of wrong type!'</span>)
<span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">'Argument is of right type but inappropriate value!'</span>)
<span class="hljs-keyword">raise</span> RuntimeError(<span class="hljs-string">'None of above!'</span>)
</code></pre></div>
<div><h3 id="userdefinedexceptions">User-defined Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyError</span><span class="hljs-params">(Exception)</span>:</span> <div><h3 id="userdefinedexceptions">User-defined Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyError</span><span class="hljs-params">(Exception)</span>:</span>
<span class="hljs-keyword">pass</span> <span class="hljs-keyword">pass</span>

Loading…
Cancel
Save