Ticket #6230: 6230_exceptions.2.diff

File 6230_exceptions.2.diff, 7.9 KB (added by viboes, 11 years ago)

new exception hierarchy

  • boost/thread/exceptions.hpp

     
    22// William E. Kempf
    33// Copyright (C) 2007-9 Anthony Williams
    44//
    5 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
     5//  Distributed under the Boost Software License, Version 1.0. (See accompanying
    66//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    77
    88#ifndef BOOST_THREAD_EXCEPTIONS_PDM070801_H
     
    1818
    1919#include <string>
    2020#include <stdexcept>
     21#include <boost/system/system_error.hpp>
     22#include <boost/system/error_code.hpp>
    2123
     24
    2225#include <boost/config/abi_prefix.hpp>
    2326
    2427namespace boost
     
    2831    {};
    2932
    3033    class BOOST_SYMBOL_VISIBLE thread_exception:
    31         public std::exception
     34        public system::system_error
     35        //public std::exception
    3236    {
    33     protected:
    34         thread_exception():
    35             m_sys_err(0)
     37          typedef system::system_error base_type;
     38    public:
     39        thread_exception()
     40          : base_type(0,system::system_category())
    3641        {}
    37    
    38         thread_exception(int sys_err_code):
    39             m_sys_err(sys_err_code)
     42
     43        thread_exception(int sys_error_code)
     44          : base_type(sys_error_code, system::system_category())
    4045        {}
    41    
    4246
    43     public:
     47        thread_exception( int ev, const char * what_arg )
     48        : base_type(system::error_code(ev, system::system_category()), what_arg)
     49        {
     50        }
     51        thread_exception( int ev, const std::string & what_arg )
     52        : base_type(system::error_code(ev, system::system_category()), what_arg)
     53        {
     54        }
     55
    4456        ~thread_exception() throw()
    4557        {}
    46    
    4758
     59
    4860        int native_error() const
    4961        {
    50             return m_sys_err;
     62            return code().value();
    5163        }
    52    
    5364
    54     private:
    55         int m_sys_err;
    5665    };
    5766
    5867    class BOOST_SYMBOL_VISIBLE condition_error:
    59         public std::exception
     68        public system::system_error
     69        //public std::exception
    6070    {
     71          typedef system::system_error base_type;
    6172    public:
    62         const char* what() const throw()
    63         {
    64             return "Condition error";
    65         }
     73          condition_error()
     74          : base_type(system::error_code(0, system::system_category()), "Condition error")
     75          {}
     76          condition_error( int ev )
     77          : base_type(system::error_code(ev, system::system_category()), "Condition error")
     78          {
     79          }
     80          condition_error( int ev, const char * what_arg )
     81          : base_type(system::error_code(ev, system::system_category()), what_arg)
     82          {
     83          }
     84          condition_error( int ev, const std::string & what_arg )
     85          : base_type(system::error_code(ev, system::system_category()), what_arg)
     86          {
     87          }
    6688    };
    67    
    6889
     90
    6991    class BOOST_SYMBOL_VISIBLE lock_error:
    7092        public thread_exception
    7193    {
     94          typedef thread_exception base_type;
    7295    public:
    7396        lock_error()
     97        : base_type(0, "boost::lock_error")
    7498        {}
    75    
    76         lock_error(int sys_err_code):
    77             thread_exception(sys_err_code)
    78         {}
    79    
     99
     100        lock_error( int ev )
     101        : base_type(ev, "boost::lock_error")
     102        {
     103        }
     104        lock_error( int ev, const char * what_arg )
     105        : base_type(ev, what_arg)
     106        {
     107        }
     108        lock_error( int ev, const std::string & what_arg )
     109        : base_type(ev, what_arg)
     110        {
     111        }
     112
    80113        ~lock_error() throw()
    81114        {}
    82    
    83115
    84         virtual const char* what() const throw()
    85         {
    86             return "boost::lock_error";
    87         }
    88116    };
    89117
    90118    class BOOST_SYMBOL_VISIBLE thread_resource_error:
    91119        public thread_exception
    92120    {
     121          typedef thread_exception base_type;
    93122    public:
    94         thread_resource_error()
    95         {}
    96    
    97         thread_resource_error(int sys_err_code):
    98             thread_exception(sys_err_code)
    99         {}
    100    
     123          thread_resource_error()
     124          : base_type(system::errc::resource_unavailable_try_again, "boost::thread_resource_error")
     125          {}
     126
     127          thread_resource_error( int ev )
     128          : base_type(ev, "boost::thread_resource_error")
     129          {
     130          }
     131          thread_resource_error( int ev, const char * what_arg )
     132          : base_type(ev, what_arg)
     133          {
     134          }
     135          thread_resource_error( int ev, const std::string & what_arg )
     136          : base_type(ev, what_arg)
     137          {
     138          }
     139
     140
    101141        ~thread_resource_error() throw()
    102142        {}
    103    
    104143
    105         virtual const char* what() const throw()
    106         {
    107             return "boost::thread_resource_error";
    108         }
    109    
    110144    };
    111145
    112146    class BOOST_SYMBOL_VISIBLE unsupported_thread_option:
    113147        public thread_exception
    114148    {
     149          typedef thread_exception base_type;
    115150    public:
    116         unsupported_thread_option()
    117         {}
    118    
    119         unsupported_thread_option(int sys_err_code):
    120             thread_exception(sys_err_code)
    121         {}
    122    
    123         ~unsupported_thread_option() throw()
    124         {}
    125    
     151          unsupported_thread_option()
     152          : base_type(system::errc::invalid_argument, "boost::unsupported_thread_option")
     153          {}
    126154
    127         virtual const char* what() const throw()
    128         {
    129             return "boost::unsupported_thread_option";
    130         }
    131    
     155          unsupported_thread_option( int ev )
     156          : base_type(ev, "boost::unsupported_thread_option")
     157          {
     158          }
     159          unsupported_thread_option( int ev, const char * what_arg )
     160          : base_type(ev, what_arg)
     161          {
     162          }
     163          unsupported_thread_option( int ev, const std::string & what_arg )
     164          : base_type(ev, what_arg)
     165          {
     166          }
     167
    132168    };
    133169
    134170    class BOOST_SYMBOL_VISIBLE invalid_thread_argument:
    135171        public thread_exception
    136172    {
     173          typedef thread_exception base_type;
    137174    public:
    138175        invalid_thread_argument()
     176        : base_type(system::errc::invalid_argument, "boost::invalid_thread_argument")
    139177        {}
    140    
    141         invalid_thread_argument(int sys_err_code):
    142             thread_exception(sys_err_code)
    143         {}
    144    
    145         ~invalid_thread_argument() throw()
    146         {}
    147    
    148178
    149         virtual const char* what() const throw()
     179        invalid_thread_argument( int ev )
     180        : base_type(ev, "boost::invalid_thread_argument")
    150181        {
    151             return "boost::invalid_thread_argument";
    152182        }
    153    
     183        invalid_thread_argument( int ev, const char * what_arg )
     184        : base_type(ev, what_arg)
     185        {
     186        }
     187        invalid_thread_argument( int ev, const std::string & what_arg )
     188        : base_type(ev, what_arg)
     189        {
     190        }
     191
    154192    };
    155193
    156194    class BOOST_SYMBOL_VISIBLE thread_permission_error:
    157195        public thread_exception
    158196    {
     197          typedef thread_exception base_type;
    159198    public:
    160         thread_permission_error()
    161         {}
    162    
    163         thread_permission_error(int sys_err_code):
    164             thread_exception(sys_err_code)
    165         {}
    166    
    167         ~thread_permission_error() throw()
    168         {}
    169    
     199          thread_permission_error()
     200          : base_type(system::errc::permission_denied, "boost::thread_permission_error")
     201          {}
    170202
    171         virtual const char* what() const throw()
    172         {
    173             return "boost::thread_permission_error";
    174         }
    175    
     203          thread_permission_error( int ev )
     204          : base_type(ev, "boost::thread_permission_error")
     205          {
     206          }
     207          thread_permission_error( int ev, const char * what_arg )
     208          : base_type(ev, what_arg)
     209          {
     210          }
     211          thread_permission_error( int ev, const std::string & what_arg )
     212          : base_type(ev, what_arg)
     213          {
     214          }
     215
    176216    };
    177217
    178218} // namespace boost