• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# JSON_NOEXCEPTION
2
3```cpp
4#define JSON_NOEXCEPTION
5```
6
7Exceptions can be switched off by defining the symbol `JSON_NOEXCEPTION`. When defining `JSON_NOEXCEPTION`, `#!cpp try`
8is replaced by `#!cpp if (true)`, `#!cpp catch` is replaced by `#!cpp if (false)`, and `#!cpp throw` is replaced by
9`#!cpp std::abort()`.
10
11The same effect is achieved by setting the compiler flag `-fno-exceptions`.
12
13## Default definition
14
15By default, the macro is not defined.
16
17```cpp
18#undef JSON_NOEXCEPTION
19```
20
21## Notes
22
23The explanatory [`what()`](https://en.cppreference.com/w/cpp/error/exception/what) string of exceptions is not
24available for MSVC if exceptions are disabled, see [#2824](https://github.com/nlohmann/json/discussions/2824).
25
26## Examples
27
28??? example
29
30    The code below switches off exceptions in the library.
31
32    ```cpp
33    #define JSON_NOEXCEPTION 1
34    #include <nlohmann/json.hpp>
35
36    ...
37    ```
38
39## See also
40
41- [Switch off exceptions](../../home/exceptions.md#switch-off-exceptions) for more information how to switch off exceptions
42
43## Version history
44
45Added in version 2.1.0.
46