Support Class Library
A set of tools providing classes and utility
Exception.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <scl/macros.h>
5 #include <utility>
6 
7 namespace scl{
8  namespace exceptions{
12  class Exception : public Throwable{
13  protected:
18  realConst(char*) _reason = "";
19 
20  public:
26  template <class T>
27  Exception(T&& reason) : _reason{std::forward<T>(reason)} {
28  }
29 
34  realConst(char*) reason() const override{
35  return this->_reason;
36  }
37 
42  const char* what() const noexcept override{
43  return this->reason();
44  }
45 
50  realConst(char*) type() const noexcept override{
51  return "scl::exceptions::Exception";
52  }
53  };
54  }
55 }
Global namespace of the SCL.
Definition: alias.hpp:3
const char *const _reason
The error message that comes with this Exception.
Definition: Exception.h:18
#define realConst(type)
Definition: macros.h:3
Exception(T &&reason)
Construct an scl::exceptions::Exception from an error message.
Definition: Exception.h:27
const char *const reason() const override
Retrieve the reason.
Definition: Exception.h:34
const char *const type() const noexcept override
A string describing the name of the exception class.
Definition: Exception.h:50
Base class for all regular exceptions.
Definition: Exception.h:12
const char * what() const noexcept override
Override that uses the user defined reason.
Definition: Exception.h:42
Base class of all throwable objects.
Definition: Throwable.h:15