ipaddress 1.1.0
|
The library provides two ways to handle errors: through exceptions and through returned error codes. Which method to choose depends on the task and policy of your project (not everywhere it is possible to use exceptions; moreover, they may even be disabled in your build).
All methods not marked noexcept
can throw exceptions; there are only a few such methods. The documentation labels them all, and also indicates the types of exceptions that can be thrown.
These are mainly methods for parsing from a string and some operations with networks from the previous section.
That's basically all you need to know about exception handling. The only thing I’ll clarify is that universal classes for addresses and networks (with union IPv4 and IPv6) first attempt to parse for IPv4, and then IPv6, which is why the error will contain information about the non-corect IPv6 (in case of exception).
If you do not use exceptions, then for all methods that can throw exceptions there are alternative methods that return an error code.
Also, your compiler may have exceptions disabled. In this case, you can also disable exceptions in the library.
IPADDRESS_NO_EXCEPTIONS
definition when building.After this, the library will not throw exceptions when errors occur. It is recommended in this case to use error codes to handle errors.
This is what the behavior will be if you pass this flag.
IPADDRESS_NO_EXCEPTIONS
flag is defined, then not all compilers can produce compile-time errors for constexpr before C++20 for parsing expressions like constexpr auto ip = ipv4_address::parse("127.0.0.257");