mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
Added 'except X as Y' to section 'except clauses' of manual (#11371)
This commit is contained in:
committed by
Andreas Rumpf
parent
3b73da310c
commit
41b74db218
@@ -3908,9 +3908,18 @@ follows a ``(`` it has to be written as a one liner:
|
||||
Except clauses
|
||||
--------------
|
||||
|
||||
Within an ``except`` clause, it is possible to use
|
||||
``getCurrentException`` to retrieve the exception that has been
|
||||
raised:
|
||||
Within an ``except`` clause it is possible to access the current exception
|
||||
using the following syntax:
|
||||
|
||||
.. 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
|
||||
try:
|
||||
@@ -3937,8 +3946,8 @@ error message from ``e``, and for such situations it is enough to use
|
||||
.. code-block:: nim
|
||||
try:
|
||||
# ...
|
||||
except IOError:
|
||||
echo "I/O error: " & getCurrentExceptionMsg()
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
||||
|
||||
Defer statement
|
||||
|
||||
Reference in New Issue
Block a user