UQTk: Uncertainty Quantification Toolkit  3.1.1
MyException.h
Go to the documentation of this file.
1 /* =====================================================================================
2 
3  The UQ Toolkit (UQTk) version 3.1.1
4  Copyright (2021) NTESS
5  https://www.sandia.gov/UQToolkit/
6  https://github.com/sandialabs/UQTk
7 
8  Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
9  Under the terms of Contract DE-NA0003525 with NTESS, the U.S. Government
10  retains certain rights in this software.
11 
12  This file is part of The UQ Toolkit (UQTk)
13 
14  UQTk is open source software: you can redistribute it and/or modify
15  it under the terms of BSD 3-Clause License
16 
17  UQTk is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  BSD 3 Clause License for more details.
21 
22  You should have received a copy of the BSD 3 Clause License
23  along with UQTk. If not, see https://choosealicense.com/licenses/bsd-3-clause/.
24 
25  Questions? Contact the UQTk Developers at <uqtk-developers@software.sandia.gov>
26  Sandia National Laboratories, Livermore, CA, USA
27 ===================================================================================== */
28 // -*- C++ -*-
29 
30 #ifndef _MyException_
31 #define _MyException_
32 
33 #include <iostream>
34 #include <exception>
35 #include <string.h>
36 
40 class MyException : public std::exception {
41 public:
43  MyException(const char* errormessage) {
44  std::cerr << "ERROR: " << errormessage << "\n";
45  error_ = std::string("MyException: ") + errormessage;
46  }
47 
49  MyException(const std::string& errormessage) {
50  std::cerr << "ERROR: " << errormessage << "\n";
51  error_ = std::string("MyException: ") + errormessage;
52  }
53 
55  virtual ~MyException() throw() {
56  }
57 
59  const char* what() const throw() {
60  try {
61  return error_.c_str();
62  } catch(...) {
63  ;
64  }
65  return error_.c_str();
66  }
67 
68 private:
69  std::string error_;
70 };
71 
72 #endif // _MyException_
Definition: MyException.h:40
MyException(const std::string &errormessage)
Construct an exception using a C++-style string.
Definition: MyException.h:49
MyException(const char *errormessage)
Construct an exception using a C-style character string.
Definition: MyException.h:43
std::string error_
Definition: MyException.h:69
virtual ~MyException()
Destroy.
Definition: MyException.h:55
const char * what() const
What's going on?
Definition: MyException.h:59