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