MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Error.hh
1 //
5 // This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6 //
7 // MARLEY is free software: you can redistribute it and/or modify it under the
8 // terms of version 3 of the GNU General Public License as published by the
9 // Free Software Foundation.
10 //
11 // For the full text of the license please see COPYING or
12 // visit http://opensource.org/licenses/GPL-3.0
13 //
14 // Please respect the MCnet academic usage guidelines. See GUIDELINES
15 // or visit https://www.montecarlonet.org/GUIDELINES for details.
16 
17 #pragma once
18 #include <exception>
19 #include <string>
20 
21 #include "marley/Logger.hh"
22 
23 namespace marley {
24 
32  class Error : public std::exception {
33  public:
36  inline explicit Error(const char* message) : msg_(message)
37  { if (log_them_) MARLEY_LOG_ERROR() << msg_; }
40  inline explicit Error(const std::string& message) : msg_(message)
41  { if (log_them_) MARLEY_LOG_ERROR() << msg_; }
42  inline virtual ~Error() {}
44  inline virtual const char* what() const noexcept { return msg_.c_str(); }
46  inline static void set_logging_status(bool do_log) { log_them_ = do_log; }
48  inline static bool logging_status() { return log_them_; }
49 
50  protected:
51 
52  std::string msg_; //< error message
53 
55  static bool log_them_;
56  };
57 }
Base class for all exceptions thrown by MARLEY functions.
Definition: Error.hh:32
Error(const std::string &message)
Definition: Error.hh:40
virtual const char * what() const noexcept
Method called by the C++ standard library to display the error message.
Definition: Error.hh:44
Error(const char *message)
Definition: Error.hh:36
static bool log_them_
If true, marley::Error messages will be printed to the Logger.
Definition: Error.hh:55
static void set_logging_status(bool do_log)
Sets whether or not error messages should be printed to the Logger.
Definition: Error.hh:46
static bool logging_status()
Returns whether or not error messages will be printed to the Logger.
Definition: Error.hh:48