Home | History | Annotate | Line # | Download | only in include
      1  1.1  joerg // -*- C++ -*-
      2  1.1  joerg //===--------------------------- stdexcept --------------------------------===//
      3  1.1  joerg //
      4  1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      5  1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      6  1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      7  1.1  joerg //
      8  1.1  joerg //===----------------------------------------------------------------------===//
      9  1.1  joerg 
     10  1.1  joerg #ifndef _LIBCPP_STDEXCEPT
     11  1.1  joerg #define _LIBCPP_STDEXCEPT
     12  1.1  joerg 
     13  1.1  joerg /*
     14  1.1  joerg     stdexcept synopsis
     15  1.1  joerg 
     16  1.1  joerg namespace std
     17  1.1  joerg {
     18  1.1  joerg 
     19  1.1  joerg class logic_error;
     20  1.1  joerg     class domain_error;
     21  1.1  joerg     class invalid_argument;
     22  1.1  joerg     class length_error;
     23  1.1  joerg     class out_of_range;
     24  1.1  joerg class runtime_error;
     25  1.1  joerg     class range_error;
     26  1.1  joerg     class overflow_error;
     27  1.1  joerg     class underflow_error;
     28  1.1  joerg 
     29  1.1  joerg for each class xxx_error:
     30  1.1  joerg 
     31  1.1  joerg class xxx_error : public exception // at least indirectly
     32  1.1  joerg {
     33  1.1  joerg public:
     34  1.1  joerg     explicit xxx_error(const string& what_arg);
     35  1.1  joerg     explicit xxx_error(const char*   what_arg);
     36  1.1  joerg 
     37  1.1  joerg     virtual const char* what() const noexcept // returns what_arg
     38  1.1  joerg };
     39  1.1  joerg 
     40  1.1  joerg }  // std
     41  1.1  joerg 
     42  1.1  joerg */
     43  1.1  joerg 
     44  1.1  joerg #include <__config>
     45  1.1  joerg #include <cstdlib>
     46  1.1  joerg #include <exception>
     47  1.1  joerg #include <iosfwd>  // for string forward decl
     48  1.1  joerg 
     49  1.1  joerg #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
     50  1.1  joerg #pragma GCC system_header
     51  1.1  joerg #endif
     52  1.1  joerg 
     53  1.1  joerg _LIBCPP_BEGIN_NAMESPACE_STD
     54  1.1  joerg 
     55  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
     56  1.1  joerg class _LIBCPP_HIDDEN __libcpp_refstring
     57  1.1  joerg {
     58  1.1  joerg     const char* __imp_;
     59  1.1  joerg 
     60  1.1  joerg     bool __uses_refcount() const;
     61  1.1  joerg public:
     62  1.1  joerg     explicit __libcpp_refstring(const char* __msg);
     63  1.1  joerg     __libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
     64  1.1  joerg     __libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
     65  1.1  joerg     ~__libcpp_refstring();
     66  1.1  joerg 
     67  1.1  joerg     const char* c_str() const _NOEXCEPT {return __imp_;}
     68  1.1  joerg };
     69  1.1  joerg #endif // !_LIBCPP_ABI_VCRUNTIME
     70  1.1  joerg 
     71  1.1  joerg _LIBCPP_END_NAMESPACE_STD
     72  1.1  joerg 
     73  1.1  joerg namespace std  // purposefully not using versioning namespace
     74  1.1  joerg {
     75  1.1  joerg 
     76  1.1  joerg class _LIBCPP_EXCEPTION_ABI logic_error
     77  1.1  joerg     : public exception
     78  1.1  joerg {
     79  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
     80  1.1  joerg private:
     81  1.1  joerg     _VSTD::__libcpp_refstring __imp_;
     82  1.1  joerg public:
     83  1.1  joerg     explicit logic_error(const string&);
     84  1.1  joerg     explicit logic_error(const char*);
     85  1.1  joerg 
     86  1.1  joerg     logic_error(const logic_error&) _NOEXCEPT;
     87  1.1  joerg     logic_error& operator=(const logic_error&) _NOEXCEPT;
     88  1.1  joerg 
     89  1.1  joerg     virtual ~logic_error() _NOEXCEPT;
     90  1.1  joerg 
     91  1.1  joerg     virtual const char* what() const _NOEXCEPT;
     92  1.1  joerg #else
     93  1.1  joerg public:
     94  1.1  joerg     explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
     95  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
     96  1.1  joerg #endif
     97  1.1  joerg };
     98  1.1  joerg 
     99  1.1  joerg class _LIBCPP_EXCEPTION_ABI runtime_error
    100  1.1  joerg     : public exception
    101  1.1  joerg {
    102  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    103  1.1  joerg private:
    104  1.1  joerg     _VSTD::__libcpp_refstring __imp_;
    105  1.1  joerg public:
    106  1.1  joerg     explicit runtime_error(const string&);
    107  1.1  joerg     explicit runtime_error(const char*);
    108  1.1  joerg 
    109  1.1  joerg     runtime_error(const runtime_error&) _NOEXCEPT;
    110  1.1  joerg     runtime_error& operator=(const runtime_error&) _NOEXCEPT;
    111  1.1  joerg 
    112  1.1  joerg     virtual ~runtime_error() _NOEXCEPT;
    113  1.1  joerg 
    114  1.1  joerg     virtual const char* what() const _NOEXCEPT;
    115  1.1  joerg #else
    116  1.1  joerg public:
    117  1.1  joerg    explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
    118  1.1  joerg    _LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
    119  1.1  joerg #endif // _LIBCPP_ABI_VCRUNTIME
    120  1.1  joerg };
    121  1.1  joerg 
    122  1.1  joerg class _LIBCPP_EXCEPTION_ABI domain_error
    123  1.1  joerg     : public logic_error
    124  1.1  joerg {
    125  1.1  joerg public:
    126  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
    127  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s)   : logic_error(__s) {}
    128  1.1  joerg 
    129  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    130  1.1  joerg     domain_error(const domain_error&) _NOEXCEPT = default;
    131  1.1  joerg     virtual ~domain_error() _NOEXCEPT;
    132  1.1  joerg #endif
    133  1.1  joerg };
    134  1.1  joerg 
    135  1.1  joerg class _LIBCPP_EXCEPTION_ABI invalid_argument
    136  1.1  joerg     : public logic_error
    137  1.1  joerg {
    138  1.1  joerg public:
    139  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
    140  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s)   : logic_error(__s) {}
    141  1.1  joerg 
    142  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    143  1.1  joerg     invalid_argument(const invalid_argument&) _NOEXCEPT = default;
    144  1.1  joerg     virtual ~invalid_argument() _NOEXCEPT;
    145  1.1  joerg #endif
    146  1.1  joerg };
    147  1.1  joerg 
    148  1.1  joerg class _LIBCPP_EXCEPTION_ABI length_error
    149  1.1  joerg     : public logic_error
    150  1.1  joerg {
    151  1.1  joerg public:
    152  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
    153  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s)   : logic_error(__s) {}
    154  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    155  1.1  joerg     length_error(const length_error&) _NOEXCEPT = default;
    156  1.1  joerg     virtual ~length_error() _NOEXCEPT;
    157  1.1  joerg #endif
    158  1.1  joerg };
    159  1.1  joerg 
    160  1.1  joerg class _LIBCPP_EXCEPTION_ABI out_of_range
    161  1.1  joerg     : public logic_error
    162  1.1  joerg {
    163  1.1  joerg public:
    164  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
    165  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s)   : logic_error(__s) {}
    166  1.1  joerg 
    167  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    168  1.1  joerg     out_of_range(const out_of_range&) _NOEXCEPT = default;
    169  1.1  joerg     virtual ~out_of_range() _NOEXCEPT;
    170  1.1  joerg #endif
    171  1.1  joerg };
    172  1.1  joerg 
    173  1.1  joerg class _LIBCPP_EXCEPTION_ABI range_error
    174  1.1  joerg     : public runtime_error
    175  1.1  joerg {
    176  1.1  joerg public:
    177  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
    178  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s)   : runtime_error(__s) {}
    179  1.1  joerg 
    180  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    181  1.1  joerg     range_error(const range_error&) _NOEXCEPT = default;
    182  1.1  joerg     virtual ~range_error() _NOEXCEPT;
    183  1.1  joerg #endif
    184  1.1  joerg };
    185  1.1  joerg 
    186  1.1  joerg class _LIBCPP_EXCEPTION_ABI overflow_error
    187  1.1  joerg     : public runtime_error
    188  1.1  joerg {
    189  1.1  joerg public:
    190  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
    191  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s)   : runtime_error(__s) {}
    192  1.1  joerg 
    193  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    194  1.1  joerg     overflow_error(const overflow_error&) _NOEXCEPT = default;
    195  1.1  joerg     virtual ~overflow_error() _NOEXCEPT;
    196  1.1  joerg #endif
    197  1.1  joerg };
    198  1.1  joerg 
    199  1.1  joerg class _LIBCPP_EXCEPTION_ABI underflow_error
    200  1.1  joerg     : public runtime_error
    201  1.1  joerg {
    202  1.1  joerg public:
    203  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
    204  1.1  joerg     _LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s)   : runtime_error(__s) {}
    205  1.1  joerg 
    206  1.1  joerg #ifndef _LIBCPP_ABI_VCRUNTIME
    207  1.1  joerg     underflow_error(const underflow_error&) _NOEXCEPT = default;
    208  1.1  joerg     virtual ~underflow_error() _NOEXCEPT;
    209  1.1  joerg #endif
    210  1.1  joerg };
    211  1.1  joerg 
    212  1.1  joerg }  // std
    213  1.1  joerg 
    214  1.1  joerg _LIBCPP_BEGIN_NAMESPACE_STD
    215  1.1  joerg 
    216  1.1  joerg // in the dylib
    217  1.1  joerg _LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
    218  1.1  joerg 
    219  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    220  1.1  joerg void __throw_logic_error(const char*__msg)
    221  1.1  joerg {
    222  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    223  1.1  joerg     throw logic_error(__msg);
    224  1.1  joerg #else
    225  1.1  joerg     ((void)__msg);
    226  1.1  joerg     _VSTD::abort();
    227  1.1  joerg #endif
    228  1.1  joerg }
    229  1.1  joerg 
    230  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    231  1.1  joerg void __throw_domain_error(const char*__msg)
    232  1.1  joerg {
    233  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    234  1.1  joerg     throw domain_error(__msg);
    235  1.1  joerg #else
    236  1.1  joerg     ((void)__msg);
    237  1.1  joerg     _VSTD::abort();
    238  1.1  joerg #endif
    239  1.1  joerg }
    240  1.1  joerg 
    241  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    242  1.1  joerg void __throw_invalid_argument(const char*__msg)
    243  1.1  joerg {
    244  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    245  1.1  joerg     throw invalid_argument(__msg);
    246  1.1  joerg #else
    247  1.1  joerg     ((void)__msg);
    248  1.1  joerg     _VSTD::abort();
    249  1.1  joerg #endif
    250  1.1  joerg }
    251  1.1  joerg 
    252  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    253  1.1  joerg void __throw_length_error(const char*__msg)
    254  1.1  joerg {
    255  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    256  1.1  joerg     throw length_error(__msg);
    257  1.1  joerg #else
    258  1.1  joerg     ((void)__msg);
    259  1.1  joerg     _VSTD::abort();
    260  1.1  joerg #endif
    261  1.1  joerg }
    262  1.1  joerg 
    263  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    264  1.1  joerg void __throw_out_of_range(const char*__msg)
    265  1.1  joerg {
    266  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    267  1.1  joerg     throw out_of_range(__msg);
    268  1.1  joerg #else
    269  1.1  joerg     ((void)__msg);
    270  1.1  joerg     _VSTD::abort();
    271  1.1  joerg #endif
    272  1.1  joerg }
    273  1.1  joerg 
    274  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    275  1.1  joerg void __throw_range_error(const char*__msg)
    276  1.1  joerg {
    277  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    278  1.1  joerg     throw range_error(__msg);
    279  1.1  joerg #else
    280  1.1  joerg     ((void)__msg);
    281  1.1  joerg     _VSTD::abort();
    282  1.1  joerg #endif
    283  1.1  joerg }
    284  1.1  joerg 
    285  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    286  1.1  joerg void __throw_overflow_error(const char*__msg)
    287  1.1  joerg {
    288  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    289  1.1  joerg     throw overflow_error(__msg);
    290  1.1  joerg #else
    291  1.1  joerg     ((void)__msg);
    292  1.1  joerg     _VSTD::abort();
    293  1.1  joerg #endif
    294  1.1  joerg }
    295  1.1  joerg 
    296  1.1  joerg _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
    297  1.1  joerg void __throw_underflow_error(const char*__msg)
    298  1.1  joerg {
    299  1.1  joerg #ifndef _LIBCPP_NO_EXCEPTIONS
    300  1.1  joerg     throw underflow_error(__msg);
    301  1.1  joerg #else
    302  1.1  joerg     ((void)__msg);
    303  1.1  joerg     _VSTD::abort();
    304  1.1  joerg #endif
    305  1.1  joerg }
    306  1.1  joerg 
    307  1.1  joerg _LIBCPP_END_NAMESPACE_STD
    308  1.1  joerg 
    309  1.1  joerg #endif // _LIBCPP_STDEXCEPT
    310