Blame view

Exception.hpp 592 Bytes
dff0a10c   Peter M. Groen   Implementation of...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #pragma once
  
  // System includes
  #include <iostream>
  #include <sstream>
  #include <stdexcept>
  #include <string>
  
  
  class Exception : public std::runtime_error 
  {
  public:
      Exception(const char *file, int line, const std::string &arg) 
          : std::runtime_error(arg) 
          {
              msg_ = std::string(file) + ":" + std::to_string(line) + ": " + arg;
          }
  
      ~Exception() throw() {}
  
      const char *what() const throw() override 
      {
          return msg_.c_str();
      }
  
  private:
      std::string msg_;
  };
  
  #define THROW_EXCEPT(arg) throw Exception(__FILE__, __LINE__, arg);