sbuild  1.7.1
custom-error.h
1 /* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org>
2  *
3  * schroot is free software: you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * schroot is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  *********************************************************************/
18 
19 #ifndef SBUILD_CUSTOM_ERROR_H
20 #define SBUILD_CUSTOM_ERROR_H
21 
22 #include <sbuild/error.h>
23 
24 namespace sbuild
25 {
26 
30  template <typename T>
31  class custom_error : public error<T>
32  {
33  public:
35  typedef typename error<T>::error_type error_type;
36 
43  sbuild::error<T>(this->format_error(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr),
44  this->format_reason(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr))
45  {
46  }
47 
54  template<typename C>
55  custom_error (C const& context,
57  sbuild::error<T>(this->format_error(context, nullptr, nullptr, error, nullptr, nullptr, nullptr),
58  this->format_reason(context, nullptr, nullptr, error, nullptr, nullptr, nullptr))
59  {
60  }
61 
68  template<typename D>
70  D const& detail):
71  sbuild::error<T>(this->format_error(nullptr, nullptr, nullptr, error, detail, nullptr, nullptr),
72  this->format_reason(nullptr, nullptr, nullptr, error, detail, nullptr, nullptr))
73  {
74  }
75 
83  template<typename D, typename E>
85  D const& detail,
86  E const& detail2):
87  sbuild::error<T>(this->format_error(nullptr, nullptr, nullptr, error, detail, detail2, nullptr),
88  this->format_reason(nullptr, nullptr, nullptr, error, detail, detail2, nullptr))
89  {
90  }
91 
100  template<typename D, typename E, typename F>
102  D const& detail,
103  E const& detail2,
104  F const& detail3):
105  sbuild::error<T>(this->format_error(nullptr, nullptr, nullptr, error, detail, detail2, detail3),
106  this->format_reason(nullptr, nullptr, nullptr, error, detail, detail2, detail3))
107  {
108  }
109 
117  template<typename C, typename D>
118  custom_error (C const& context,
120  D const& detail):
121  sbuild::error<T>(this->format_error(context, nullptr, nullptr, error, detail, nullptr, nullptr),
122  this->format_reason(context, nullptr, nullptr, error, detail, nullptr, nullptr))
123  {
124  }
125 
134  template<typename C, typename D, typename E>
135  custom_error (C const& context,
137  D const& detail,
138  E const& detail2):
139  sbuild::error<T>(format_error(context, nullptr, nullptr, error, detail, detail2, nullptr),
140  format_reason(context, nullptr, nullptr, error, detail, detail2, nullptr))
141  {
142  }
143 
152  template<typename C, typename D, typename E>
153  custom_error (C const& context1,
154  D const& context2,
156  E const& detail):
157  sbuild::error<T>(this->format_error(context1, context2, nullptr, error, detail, nullptr, nullptr),
158  this->format_reason(context1, context2, nullptr, error, detail, nullptr, nullptr))
159  {
160  }
161 
171  template<typename C, typename D, typename E, typename F>
172  custom_error (C const& context1,
173  D const& context2,
175  E const& detail,
176  F const& detail2):
177  sbuild::error<T>(format_error(context1, context2, nullptr, error, detail, detail2, nullptr),
178  format_reason(context1, context2, nullptr, error, detail, detail2, nullptr))
179  {
180  }
181 
187  custom_error (const std::runtime_error& error):
188  sbuild::error<T>(sbuild::error<T>::format_error(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr),
189  sbuild::error<T>::format_reason(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr))
190  {
191  }
192 
199  sbuild::error<T>(sbuild::error<T>::format_error(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr),
200  sbuild::error<T>::format_reason(nullptr, nullptr, nullptr, error, nullptr, nullptr, nullptr))
201  {
202  }
203 
210  template<typename C>
211  custom_error (C const& context,
212  const std::runtime_error& error):
213  sbuild::error<T>(sbuild::error<T>::format_error(context, nullptr, nullptr, error, nullptr, nullptr, nullptr),
214  sbuild::error<T>::format_reason(context, nullptr, nullptr, error, nullptr, nullptr, nullptr))
215  {
216  }
217 
224  template<typename C>
225  custom_error (C const& context,
226  const error_base& error):
227  sbuild::error<T>(sbuild::error<T>::format_error(context, nullptr, nullptr, error, nullptr, nullptr, nullptr),
228  sbuild::error<T>::format_reason(context, nullptr, nullptr, error, nullptr, nullptr, nullptr))
229  {
230  }
231 
233  virtual ~custom_error () throw ()
234  {}
235  };
236 
237 }
238 
239 #endif /* SBUILD_CUSTOM_ERROR_H */
240 
241 /*
242  * Local Variables:
243  * mode:C++
244  * End:
245  */