Added 'except X as Y' to section 'except clauses' of manual (#11371)
This commit is contained in:
parent
3b73da310c
commit
41b74db218
1 changed files with 14 additions and 5 deletions
|
|
@ -3908,9 +3908,18 @@ follows a ``(`` it has to be written as a one liner:
|
||||||
Except clauses
|
Except clauses
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Within an ``except`` clause, it is possible to use
|
Within an ``except`` clause it is possible to access the current exception
|
||||||
``getCurrentException`` to retrieve the exception that has been
|
using the following syntax:
|
||||||
raised:
|
|
||||||
|
.. code-block:: nim
|
||||||
|
try:
|
||||||
|
# ...
|
||||||
|
except IOError as e:
|
||||||
|
# Now use "e"
|
||||||
|
echo "I/O error: " & e.msg
|
||||||
|
|
||||||
|
Alternatively, it is possible to use ``getCurrentException`` to retrieve the
|
||||||
|
exception that has been raised:
|
||||||
|
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
try:
|
try:
|
||||||
|
|
@ -3937,8 +3946,8 @@ error message from ``e``, and for such situations it is enough to use
|
||||||
.. code-block:: nim
|
.. code-block:: nim
|
||||||
try:
|
try:
|
||||||
# ...
|
# ...
|
||||||
except IOError:
|
except:
|
||||||
echo "I/O error: " & getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
|
|
||||||
Defer statement
|
Defer statement
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue