Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
numeric_error.h
1#ifndef SOURCEMETA_CORE_NUMERIC_ERROR_H
2#define SOURCEMETA_CORE_NUMERIC_ERROR_H
3
4#ifndef SOURCEMETA_CORE_NUMERIC_EXPORT
5#include <sourcemeta/core/numeric_export.h>
6#endif
7
8#include <exception> // std::exception
9#include <stdexcept> // std::out_of_range
10
11namespace sourcemeta::core {
12
13// Exporting symbols that depends on the standard C++ library is considered
14// safe.
15// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
16#if defined(_MSC_VER)
17#pragma warning(disable : 4251 4275)
18#endif
19
22class SOURCEMETA_CORE_NUMERIC_EXPORT DecimalParseError : public std::exception {
23public:
24 [[nodiscard]] auto what() const noexcept -> const char * override {
25 return "Invalid decimal string format";
26 }
27};
28
31class SOURCEMETA_CORE_NUMERIC_EXPORT NumericDivisionByZeroError
32 : public std::exception {
33public:
34 [[nodiscard]] auto what() const noexcept -> const char * override {
35 return "Division by zero";
36 }
37};
38
41class SOURCEMETA_CORE_NUMERIC_EXPORT NumericInvalidOperationError
42 : public std::exception {
43public:
44 [[nodiscard]] auto what() const noexcept -> const char * override {
45 return "Invalid numeric operation";
46 }
47};
48
51class SOURCEMETA_CORE_NUMERIC_EXPORT NumericOverflowError
52 : public std::exception {
53public:
54 [[nodiscard]] auto what() const noexcept -> const char * override {
55 return "Numeric overflow";
56 }
57};
58
62class SOURCEMETA_CORE_NUMERIC_EXPORT NumericOutOfRangeError
63 : public std::out_of_range {
64public:
65 NumericOutOfRangeError()
66 : std::out_of_range{"Numeric value is out of range"} {}
67};
68
71class SOURCEMETA_CORE_NUMERIC_EXPORT NumericOutOfMemoryError
72 : public std::exception {
73public:
74 [[nodiscard]] auto what() const noexcept -> const char * override {
75 return "Out of memory";
76 }
77};
78
79#if defined(_MSC_VER)
80#pragma warning(default : 4251 4275)
81#endif
82
83} // namespace sourcemeta::core
84
85#endif
Definition numeric_error.h:22
Definition numeric_error.h:72
Definition numeric_error.h:52