Flow123d  release_1.8.2-1603-g0109a2b
exceptions.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file exceptions.cc
15  * @brief
16  */
17 
18 #include "system.hh"
19 #include "exceptions.hh"
20 #include <iostream>
21 #include <cstring>
22 #include <boost/exception/diagnostic_information.hpp>
23 
24 
26  this->frames_to_cut_ = { "boost", "exception_detail", "throw_exception"};
27 }
28 
29 
30 
33 
34 
35 
36 
38 
39 
40 
41 
42 void ExceptionBase::print_stacktrace(std::ostream &out) const {
44 }
45 
46 
47 const char * ExceptionBase::what() const throw () {
48  // have preallocated some space for error message we want to return
49  // Is there any difference, if we move this into ExceptionBase ??
50  static std::string message(1024,' ');
51 
52  // Be sure that this function do not throw.
53  try {
54  std::ostringstream converter;
55 
56  converter << std::endl << std::endl;
57  converter << "--------------------------------------------------------" << std::endl;
58  converter << this->what_type_msg();
59  print_info(converter);
60 
61  converter << "\n** Diagnosting info **\n" ;
62  converter << boost::diagnostic_information_what( *this );
63  print_stacktrace(converter);
64  converter << "--------------------------------------------------------" << std::endl;
65 
66  message = converter.str();
67  return message.c_str();
68 
69  } catch (std::exception &exc) {
70  std::cerr << "*** Exception encountered in exception handling routines ***" << std::endl << "*** Message is " << std::endl
71  << exc.what() << std::endl << "*** Aborting! ***" << std::endl;
72 
73  std::abort();
74  } catch (...) {
75  std::cerr << "*** Exception encountered in exception handling routines ***" << std::endl << "*** Aborting! ***"
76  << std::endl;
77 
78  std::abort();
79  }
80  return 0;
81 }
82 
83 
84 std::string ExceptionBase::what_type_msg() const {
85  return "Program Error: ";
86 }
87 
88 
89 
virtual const char * what() const
Definition: exceptions.cc:47
ExceptionBase()
Default constructor, just calls fill_stacktrace().
Definition: exceptions.cc:25
void print(std::ostream &out, std::vector< std::string > frames_to_cut=std::vector< std::string >()) const
Prints formated stacktrace into given stream out.
Definition: stack_trace.cc:71
StackTrace stack_trace_
Stacktrace of exception.
Definition: exceptions.hh:93
std::vector< std::string > frames_to_cut_
Stacktrace frames, which will be cut, see StackTrace::print method.
Definition: exceptions.hh:95
virtual std::string what_type_msg() const
Return type of message ("Program error" for this class). Can be override in descendants.
Definition: exceptions.cc:84
virtual void print_info(std::ostringstream &out) const =0
virtual ~ExceptionBase()
Destructor, possibly free stacktrace.
Definition: exceptions.cc:37
Base of exceptions used in Flow123d.
Definition: exceptions.hh:66
void print_stacktrace(std::ostream &out) const
Prints formated stacktrace into given stream out.
Definition: exceptions.cc:42