mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
29e4b82b4a
More documentation on how things work. Once more at a 'feature-complete' state. Continue to work on #116. Add testcase to ensure #108 is fixed. Then, prep release.
15 lines
855 B
ReStructuredText
15 lines
855 B
ReStructuredText
error
|
|
=====
|
|
the single error/exception type
|
|
-------------------------------
|
|
|
|
.. code-block:: cpp
|
|
|
|
class error : public std::runtime_error {
|
|
public:
|
|
error(const std::string& str): std::runtime_error("Lua: error: " + str) {}
|
|
};
|
|
|
|
If an eror is thrown by Sol, it is going to be of this type. We use this in a single place: the default ``at_panic`` function we bind on construction of a :ref:`sol::state<set-panic>`. If you turn :doc:`off exceptions<../exceptions>`, the chances of you seeing this error are :doc:`nil<types>`.
|
|
|
|
As it derives from ``std::runtime_error``, which derives from ``std::exception``, you can catch it with a ``catch (const std::exception& )`` clause in your try/catch blocks. You can retrieve a string error from Lua (Lua pushes all its errors as string returns) by using this type with any of the get or lookup functions in Sol. |