Skip to content

Commit 84322a1

Browse files
committed
[doc] Add reference page about error handling
1 parent 7cd5261 commit 84322a1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Error handling
2+
==============
3+
4+
Inexor uses `exceptions <https://www.cplusplus.com/reference/exception/exception/>`__ as for error handling, as it is proposed by the `C++ core guidelines <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-errors>`__. It should only be used for error handling and mainly in code areas which are not performance critical. It also should only be used for *exceptional errors*, which can't be ignored easily. Exceptions are not without criticism, but all alternatives (like return codes for examples) are not free either. In some areas, as in constructors for example, no return codes can be used at all. A detailed discussion why to use exceptions can be found `here <https://isocpp.org/wiki/faq/exceptions>`__.
5+
6+
Spdlog
7+
------
8+
9+
- Inexor uses `spdlog <https://github.com/gabime/spdlog>`__ for console output and log messages
10+
- Use ``spdlog::trace``, ``spdlog::debug``, ``spdlog::info``, ``spdlog::warning``, ``spdlog::error``, and ``spdlog::critical``
11+
12+
Custom exception classes
13+
------------------------
14+
15+
- Inexor has a custom base class for exceptions called ``InexorException`` which inherits from ``std::runtime_error``
16+
- For exceptions which are thrown because a Vulkan function call failed, ``VulkanException`` is used
17+
- ``VulkanException`` constructor takes an error message as ``std::string`` and the ``VkResult`` value
18+
- The constructor of ``VulkanException`` will turn the ``VkResult`` into a human readable error message (like ``VK_ERROR_INITIALIZATION_FAILED``) and a user friendly error description (in this case "Initialization of an object could not be completed for implementation-specific reasons.")
19+
- In order to be able to pass the ``VkResult`` of a Vulkan function call to the exception, it should be stored in a `C++17 if statement with initializer <https://en.cppreference.com/w/cpp/language/if>`__ (see example)
20+
21+
**Example**
22+
23+
.. code-block:: cpp
24+
25+
if (const auto result = vkEnumerateInstanceLayerProperties(&instance_layer_count, nullptr); result != VK_SUCCESS) {
26+
throw VulkanException("Error: vkEnumerateInstanceLayerProperties failed!", result);
27+
}
28+
29+
Example result: ``Error: vkEnumerateInstanceLayerProperties failed! (VK_ERROR_OUT_OF_HOST_MEMORY: A host memory allocation has failed.)``

documentation/source/development/reference/main.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Reference
55
.. toctree::
66
:maxdepth: 1
77

8-
gpu-selection
98
binary-format-specification
9+
error-handling
10+
gpu-selection
1011
keyboard-mouse-input
1112
octree-file-format

0 commit comments

Comments
 (0)