GGEMS  1.1
GPU GEant4-based Monte Carlo Simulations
GGEMSTools.cc
Go to the documentation of this file.
1 // ************************************************************************
2 // * This file is part of GGEMS. *
3 // * *
4 // * GGEMS 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 // * GGEMS 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 GGEMS. If not, see <https://www.gnu.org/licenses/>. *
16 // * *
17 // ************************************************************************
18 
31 #include <sstream>
32 #include <cerrno>
33 #include <cstring>
34 
37 
41 
42 void GGEMSFileStream::CheckInputStream(std::ifstream const& input_stream, std::string const& filename)
43 {
44  if (!input_stream) {
45  std::ostringstream oss(std::ostringstream::out);
46  #ifdef _WIN32
47  char buffer_error[ 256 ];
48  strerror_s(buffer_error, 256, errno);
49  oss << "Problem reading filename '" << filename << "': " << buffer_error;
50  #else
51  oss << "Problem reading filename '" << filename << "': " << strerror(errno);
52  #endif
53  GGEMSMisc::ThrowException("", "", oss.str());
54  }
55 }
56 
60 
61 void GGEMSMisc::ThrowException(std::string const& class_name, std::string const& method_name, std::string const& message)
62 {
63  std::ostringstream oss(std::ostringstream::out);
64  oss << message;
65  GGcerr(class_name, method_name, 0) << oss.str() << GGendl;
66  throw std::runtime_error("");
67 }
GGEMSTools.hh
Namespaces for different useful fonctions.
GGcerr
GGEMSStream GGcerr
Definition: GGEMSPrint.cc:35
GGendl
#define GGendl
overload C++ std::endl
Definition: GGEMSPrint.hh:60
GGEMSPrint.hh
Print a custom std::cout end std::cerr handling verbosity.
GGEMSFileStream::CheckInputStream
void CheckInputStream(std::ifstream const &input_stream, std::string const &filename)
check the input stream during the opening
Definition: GGEMSTools.cc:42
GGEMSMisc::ThrowException
void ThrowException(std::string const &class_name, std::string const &method_name, std::string const &message)
Throw a C++ exception.
Definition: GGEMSTools.cc:61