libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
exception_impl.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
20 
21 namespace jmmcg { namespace LIBJMMCG_VER_NAMESPACE {
22 
23  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
24  exception<API, Mdl>::exception(tstring &&r, info::function &&f, info::revision &&ri) noexcept(false)
25  : base_t(TStringToString(to_string(r, f, ri, thread_traits::get_current_process_id(), thread_traits::get_current_thread_id(), thread_traits::get_current_username()))),
26  process_id(thread_traits::get_current_process_id()),
27  thread_id(thread_traits::get_current_thread_id()),
28  current_username{thread_traits::get_current_username()},
29  reason(std::move(r)),
30  func(std::move(f)),
31  rev(std::move(ri)) {
32  what_.reserve(reason.size()+max_size());
33  }
34 
35  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
36  exception<API, Mdl>::exception(const tostringstream &r, info::function &&f, info::revision &&ri) noexcept(false)
37  : base_t(TStringToString(to_string(r.str(), std::move(f), std::move(ri), thread_traits::get_current_process_id(), thread_traits::get_current_thread_id()))),
38  process_id(thread_traits::get_current_process_id()),
39  thread_id(thread_traits::get_current_thread_id()),
40  current_username{thread_traits::get_current_username()},
41  reason(r.str()),
42  func(f),
43  rev(ri) {
44  what_.reserve(reason.size()+1024 /* A blatant guess. */);
45  }
46 
47  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
48  exception<API, Mdl>::exception(const exception &ex) noexcept(false)
49  : base_t(static_cast<exception::base_t const &>(ex)),
50  process_id(ex.process_id),
51  thread_id(ex.thread_id),
52  current_username(ex.current_username),
53  reason(ex.reason),
54  func(ex.func),
55  rev(ex.rev),
56  what_(ex.what_) {
57  }
58 
59  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
60  const tstring __fastcall
61  exception<API, Mdl>::to_string() const noexcept(false) {
62  return to_string(reason, func, rev, process_id, thread_id, current_username);
63  }
64 
65  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
66  char const * __CLR_OR_THIS_CALL
67  exception<API, Mdl>::what() const noexcept(true) {
68  try {
69  what_=TStringToString(this->to_string());
70  return what_.c_str();
71  } catch (...) {
72  return "what(): Unable to convert to string.";
73  }
74  }
75 
76  inline NEVER_INLINE const tstring __fastcall
77  dump_crt_errno(const unsigned long err) noexcept(false) {
79  o<<_T("\nCRT errno: 0x")<<std::hex<<err<<_T("; string translation: '")<<::strerror(err)<<_T("'.\n");
80  return o.str();
81  }
82 
83  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
84  crt_exception<API, Mdl>::crt_exception(tstring &&r, info::function &&f, info::revision &&ri, const unsigned long en) noexcept(false)
85  : base_t(std::move(r), std::move(f), std::move(ri)), crt_errno(en) {
86  }
87 
88  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
89  crt_exception<API, Mdl>::crt_exception(const tostringstream &r, info::function &&f, info::revision &&ri,const unsigned long en) noexcept(false)
90  : base_t(r, std::move(f), std::move(ri)), crt_errno(en) {
91  }
92 
93  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
94  crt_exception<API, Mdl>::crt_exception(const crt_exception &ex) noexcept(false)
95  : base_t(ex), crt_errno(ex.crt_errno) {
96  }
97 
98  template<ppd::generic_traits::api_type API, typename Mdl> inline NEVER_INLINE
99  const tstring __fastcall
100  crt_exception<API, Mdl>::to_string() const noexcept(false) {
101  tostringstream o;
102  o<<dump_crt_errno(crt_errno)<<base_t::to_string();
103  return o.str();
104  }
105 
106 } }