Turi Create  4.0
error_types.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef CPPIPC_COMMON_ERROR_TYPES_HPP
7 #define CPPIPC_COMMON_ERROR_TYPES_HPP
8 #include <string>
9 #include <exception>
10 #include <typeinfo>
11 #include <core/export.hpp>
12 namespace turi {
13 
14 /**
15  * Subclass the std::bad_alloc with custom message.
16  */
17 class EXPORT bad_alloc : public std::bad_alloc {
18 
19  std::string msg;
20 
21  public:
22  bad_alloc(const std::string& msg) : msg(msg) {}
23  virtual const char* what() const throw() {
24  return msg.c_str();
25  }
26 };
27 
28 /**
29  * Subclass the std::bad_cast with custom message.
30  */
31 class EXPORT bad_cast : public std::bad_cast {
32 
33  std::string msg;
34 
35  public:
36  bad_cast(const std::string& msg) : msg(msg) {}
37  virtual const char* what() const throw() {
38  return msg.c_str();
39  }
40 };
41 
42 } // cppipc
43 #endif