Support Class Library
A set of tools providing classes and utility
Throwable.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <exception>
4 #include <string>
5 #include <scl/macros.h>
6 #include <scl/utils/toString.h>
9 
10 namespace scl{
11  namespace exceptions{
15  struct Throwable : public virtual std::exception{
20  virtual realConst(char*) reason() const{
21  return std::exception::what();
22  }
23 
28  virtual realConst(char*) type() const noexcept = 0;
29  };
30  }
31 
32  namespace utils{
36  template <class T>
38  META::is_base_of<scl::exceptions::Throwable, T>()
39  >>{
40  std::string operator()(const T& t) const{
41  return std::string{t.type()} + " : " + t.reason();
42  }
43  };
44  }
45 }
46 
47 /*std::ostream& operator<<(std::ostream& os, scl::exceptions::Throwable& t){
48  return os << scl::utils::toString<scl::exceptions::Throwable>(t);
49 }*/
50 
51 //#ifdef SCL_USE_IOSTREAM_EXTEND
52 //namespace std{
53 // string to_string(const scl::exceptions::Throwable& t){
54 // return std::string{t.type()} + " : " + t.reason();
55 // }
56 //}
57 //#endif
Global namespace of the SCL.
Definition: alias.hpp:3
#define META
Definition: macros.h:8
virtual const char *const reason() const
Retrieve the reason.
Definition: Throwable.h:20
#define realConst(type)
Definition: macros.h:3
virtual const char *const type() const noexcept=0
The name of this Throwable type.
Base class of all throwable objects.
Definition: Throwable.h:15
typename std::enable_if< B, T >::type enable_if_t
An handy type alias for the result of std::enable_if.
Definition: enable_if.h:12