Exceptions: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 625: | Line 625: | ||
===Throwing an exception=== |
===Throwing an exception=== |
||
{{works with|Python|2.x and 3.x}} |
|||
Creating an exception using the default constructor of an exception class: |
|||
⚫ | |||
⚫ | |||
{{works with|Python|2.5}} |
|||
⚫ | |||
Passing an argument to the constructor of an exception class: |
|||
⚫ | |||
<lang python>def spam(): |
|||
raise SillyError, 'egg' # equivalent to raise SillyError('egg')</lang> |
|||
The above syntax is removed in Python 3.0; but the following syntax works in Python 2.x and 3.x, so should be preferred. |
|||
{{works with|Python|2.x and 3.x}} |
|||
<lang python>def spam(): |
|||
raise SillyError('egg')</lang> |
|||
===Handling an exception=== |
===Handling an exception=== |