Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Martin Rupp
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #include "error.h"
34 : #include <typeinfo>
35 : #include <new>
36 : #include <stdexcept>
37 : namespace ug{
38 :
39 0 : std::string ErrorStringFromStdException(const std::exception *pex)
40 : {
41 0 : std::stringstream ss;
42 0 : if(dynamic_cast<const std::bad_alloc*>(pex))
43 0 : ss << "bad_alloc exception: " << pex->what() << "\nThis is mostly caused by an OUT OF MEMORY - condition.\n"\
44 0 : << "You might have to reduce your problem size, go parallel or increase memory.";
45 0 : if(dynamic_cast<const std::bad_typeid*>(pex))
46 0 : ss << "bad_typeid exception: " << pex->what();
47 0 : else if(dynamic_cast<const std::bad_cast*>(pex))
48 0 : ss << "bad_cast exception: " << pex->what() << "\nThis is caused by a casting error in classes: "
49 0 : "An object is expected to be be or derive from class A, but is not.";
50 0 : else if(dynamic_cast<const std::bad_exception*>(pex))
51 0 : ss << "bad_exception exception: " << pex->what() << "\nException thrown by unexpected handler.";
52 0 : else if(dynamic_cast<const std::runtime_error*>(pex))
53 0 : ss << "runtime_error exception: " << pex->what();
54 0 : else if(dynamic_cast<const std::logic_error*>(pex))
55 : {
56 0 : if(dynamic_cast<const std::out_of_range*>(pex))
57 0 : ss << "out_of_range exception: " << pex->what();
58 0 : else if(dynamic_cast<const std::length_error*>(pex))
59 0 : ss << "length_error exception: " << pex->what();
60 : else
61 0 : ss << "logic_error exception: " << pex->what();
62 : }
63 : else
64 : {
65 0 : ss << "Unknown std::exception: " << pex->what();
66 : }
67 0 : return ss.str();
68 0 : }
69 :
70 0 : UGError::UGError(const std::string &msg, const std::exception &ex, const char *file, const unsigned long line)
71 : {
72 0 : push_msg(ErrorStringFromStdException(&ex), file, line);
73 0 : push_msg(msg, file, line);
74 0 : }
75 : }
|