| | 51 | |
| | 52 | === Raise Exceptions Instances === |
| | 53 | |
| | 54 | Python-3 does no longer support the {{{raise E, V, T}}} syntax - the new syntax is {{{raise E(V).with_traceback(T)}}}. |
| | 55 | |
| | 56 | However, the traceback is rarely required - and where E is an Exception class (rather than a string), we can use the {{{raise E(V)}}} syntax which works in all Python versions. |
| | 57 | |
| | 58 | {{{#!python |
| | 59 | # Works in Py2, but not in Py3: |
| | 60 | raise SyntaxError, "Error Message" |
| | 61 | |
| | 62 | # Works in all Python versions, hence our Standard: |
| | 63 | raise SyntaxError("Error Message") |
| | 64 | }}} |
| | 65 | |
| | 66 | If a traceback object must be passed (which is rarely needed), then we must use the PY2 constant to implement alternative statements. |
| 82 | | === Raise Exceptions Instances === |
| 83 | | |
| 84 | | Python-3 does no longer support the {{{raise E, V, T}}} syntax - the new syntax is {{{raise E(V).with_traceback(T)}}}. |
| 85 | | |
| 86 | | However, the traceback is rarely required - and where E is an Exception class (rather than a string), we can use the {{{raise E(V)}}} syntax which works in all Python versions. |
| 87 | | |
| 88 | | {{{#!python |
| 89 | | # Works in Py2, but not in Py3: |
| 90 | | raise SyntaxError, "Error Message" |
| 91 | | |
| 92 | | # Works in all Python versions, hence our Standard: |
| 93 | | raise SyntaxError("Error Message") |
| 94 | | }}} |
| 95 | | |
| 96 | | If a traceback object must be passed (which is rarely needed), then we must use the PY2 constant to implement alternative statements. |