BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSException.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSEXCEPTION_H
20#define BDSEXCEPTION_H
21
22#include <exception>
23#include <string>
24
34class BDSException: public std::exception
35{
36public:
37 explicit BDSException(const std::string& messageIn) noexcept:
38 name(""),
39 message(messageIn),
40 completeString(messageIn)
41 {;}
42 BDSException(const std::string& nameIn, const std::string& messageIn) noexcept:
43 name(nameIn),
44 message(messageIn),
45 completeString(nameIn + " : " + messageIn)
46 {;}
47 BDSException(const BDSException& other) noexcept:
48 name(other.name),
49 message(other.message),
51 {;}
52 virtual ~BDSException(){;}
53
55 const char* what() const noexcept override
56 {return name.empty() ? message.c_str() : completeString.c_str();}
57
59 void SetName(const std::string& nameIn) {name = nameIn; completeString = nameIn + " : " + message;}
60 void AppendToMessage(const std::string& messageIn) {message += " " + messageIn; completeString += " " + messageIn;}
61
63 std::string name;
64 std::string message;
65 std::string completeString;
67};
68
69#endif
General exception with possible name of object and message.
Definition: BDSException.hh:35
std::string name
Data to print.
Definition: BDSException.hh:63
const char * what() const noexcept override
Override message in std::exception.
Definition: BDSException.hh:55
std::string completeString
Data to print.
Definition: BDSException.hh:65
void SetName(const std::string &nameIn)
Allow setting of name later.
Definition: BDSException.hh:59
std::string message
Data to print.
Definition: BDSException.hh:64