Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a note + eg about custom exceptions #12847

Merged
merged 1 commit into from
Dec 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4129,6 +4129,23 @@ error message from ``e``, and for such situations it is enough to use
except:
echo getCurrentExceptionMsg()

Custom exceptions
-----------------

Is it possible to create custom exceptions. These make it easy to distinguish between exceptions raised by nim and those from your own code.

A custom exception is a custom type:

.. code-block:: nim
type
LoadError* = object of Exception

Ending the custom exception's name with ``Error`` is recommended.

Custom exceptions can be raised like any others, e.g.:

.. code-block:: nim
raise newException(LoadError, "Failed to load data")

Defer statement
---------------
Expand Down