CEPS  24.01
Cardiac ElectroPhysiology Simulator
CepsException.cpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
34 
35 CepsException::CepsException(const CepsString& message, CepsBool warn, std::source_location loc):
36  std::runtime_error(message),
37  m_loc(loc),
38  m_warning(warn)
39 {
40  // The message won't be displayed otherwise (exception caught by TS_ASSERT_TRHOWS)
41  if (ceps::isMaster() and flags->testing() and not m_warning)
42  std::cerr << errorMessage() << std::endl;
43 }
44 
47 {
48 
49  std::stringstream flpf;
50  flpf << CEPS_STRING_SEPARATOR << "\n";
51  if (m_warning)
52  flpf << (color ? CEPS_COLORED_WARNING : CEPS_WARNING);
53  else
54  flpf << (color ? CEPS_COLORED_ERROR : CEPS_ERROR);
55 
56  flpf << "\n · in file " << m_loc.file_name() << ":" << m_loc.line()
57  << "\n · from process " << ceps::getRank()
58  << "\n · in function " << m_loc.function_name() << " :\n "
59  << what();
60 
61  return flpf.str();
62 
63 }
64 
#define CEPS_WARNING
CepsString used as message for warnings.
#define CEPS_COLORED_ERROR
CepsString used as colored message for errors.
#define CEPS_COLORED_WARNING
CepsString used as colored message for warnings.
#define CEPS_STRING_SEPARATOR
CepsString used as separator.
#define CEPS_ERROR
CepsString used as message for errors.
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
Flags * flags
Global variable, used in every application.
Definition: ceps.cpp:34
CepsBool m_warning
std::source_location m_loc
CepsException(const CepsString &message="", CepsBool warning=false, std::source_location loc=std::source_location::current())
Constructor with message and location of instantiation in source files.
CepsString errorMessage(CepsBool color=true) const
Nice display of error.
CepsBool testing() const
Tells if currently running in a test suite (switched in CepsGlobalFixture.hpp)
Definition: CepsFlags.cpp:189
CepsUInt getRank()
Returns current processor rank.
CepsBool isMaster()
Is calling process the master ?