MarlinMT  0.1.0
Exceptions.cc
Go to the documentation of this file.
1 #include <marlinmt/Exceptions.h>
2 
3 namespace marlinmt {
4 
5  Exception::Exception( const std::string &message ) :
6  _message(message) {
7  /* nop */
8  }
9 
10  //--------------------------------------------------------------------------
11 
12  Exception::Exception( unsigned int line, const std::string &func, const std::string &fname, const std::string &message ) :
13  _message(createMessage(line, func, fname, message)) {
14  /* nop */
15  }
16 
17  //--------------------------------------------------------------------------
18 
19  const char* Exception::what() const noexcept {
20  return _message.c_str() ;
21  }
22 
23  //--------------------------------------------------------------------------
24 
25  std::string Exception::createMessage( unsigned int line, const std::string &func, const std::string &fname, const std::string &message ) const {
26  return "in file: " + fname + " (l." + std::to_string(line) + ")\nin function: " + func + "\nmessage: " + message ;
27  }
28 
29  //--------------------------------------------------------------------------
30 
31  std::string Exception::createMessage( const std::string &previous, unsigned int line, const std::string &func, const std::string &fname, const std::string &message ) const {
32  if( previous.empty() ) {
33  return createMessage(line, func, fname, message) ;
34  }
35  else {
36  return previous + "\n" + createMessage(line, func, fname, message) ;
37  }
38  }
39 
40 }
const char * what() const noexcept override
Get the full exception message.
Definition: Exceptions.cc:19
std::string createMessage(unsigned int line, const std::string &func, const std::string &fname, const std::string &message) const
Helper function creating the full exception message.
Definition: Exceptions.cc:25
const std::string _message
< The full exception message
Definition: Exceptions.h:124