Skip to content
Snippets Groups Projects
Commit 622dbbda authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

Merge branch 'feature/dune-exception-derived-from-std-exception' into 'master'

Feature/dune exception derived from std exception

I almost missed Christian's last commit. It was poor luck :four_leaf_clover: that I had a look into the commit history before replacing the old remote URL by the new, Gitlab-based one. I manually transferred his commit and saved myself the work of programming what Christian already did.

See merge request !2
parents a8c65a5b 0da225ef
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,38 @@
#include <dune/common/exceptions.hh>
namespace Dune {
// static member of Dune::Exception
/*
static member of Dune::Exception
*/
ExceptionHook * Exception::_hook = 0;
/*
Implementation of Dune::Exception
*/
Exception::Exception ()
{
// call the hook if necessary
if (_hook != 0) _hook->operator()();
}
void Exception::registerHook (ExceptionHook * hook)
{
_hook = hook;
}
void Exception::clearHook ()
{
_hook = 0;
}
void Exception::message(const std::string & msg)
{
_message = msg;
}
const char* Exception::what() const noexcept
{
return _message.data();
}
}
......@@ -4,6 +4,7 @@
#ifndef DUNE_EXCEPTIONS_HH
#define DUNE_EXCEPTIONS_HH
#include <exception>
#include <string>
#include <sstream>
......@@ -88,13 +89,15 @@ namespace Dune {
\see DUNE_THROW, IOError, MathError
*/
class Exception {
class Exception
: public std::exception
{
public:
Exception ();
void message(const std::string &msg); //!< store string in internal message buffer
const std::string& what() const; //!< output internal message buffer
virtual const char* what() const noexcept; //!< output internal message buffer
static void registerHook (ExceptionHook * hook); //!< add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook) \see Dune::ExceptionHook
static void clearHook (); //!< remove all hooks
static void clearHook (); //!< remove all hooks
private:
std::string _message;
static ExceptionHook * _hook;
......@@ -171,36 +174,6 @@ namespace Dune {
virtual void operator () () = 0;
};
/*
Implementation of Dune::Exception
*/
inline Exception::Exception ()
{
// call the hook if necessary
if (_hook != 0) _hook->operator()();
}
inline void Exception::registerHook (ExceptionHook * hook)
{
_hook = hook;
}
inline void Exception::clearHook ()
{
_hook = 0;
}
inline void Exception::message(const std::string & msg)
{
_message = msg;
}
inline const std::string& Exception::what() const
{
return _message;
}
inline std::ostream& operator<<(std::ostream &stream, const Exception &e)
{
return stream << e.what();
......
......@@ -22,7 +22,8 @@ dune_add_test(NAME check_fvector_size_fail2
COMPILE_DEFINITIONS DIM=3
EXPECT_COMPILE_FAIL)
dune_add_test(SOURCES classnametest.cc)
dune_add_test(SOURCES classnametest.cc
LINK_LIBRARIES dunecommon)
dune_add_test(SOURCES conversiontest.cc)
......@@ -32,7 +33,8 @@ dune_add_test(SOURCES diagonalmatrixtest.cc
dune_add_test(SOURCES dynmatrixtest.cc
LINK_LIBRARIES dunecommon)
dune_add_test(SOURCES dynvectortest.cc)
dune_add_test(SOURCES dynvectortest.cc
LINK_LIBRARIES dunecommon)
dune_add_test(SOURCES enumsettest.cc)
......
......@@ -3,10 +3,13 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/common/fvector.hh>
#include <dune/common/classname.hh>
#include <iostream>
#include <complex>
#include <iostream>
#include <dune/common/classname.hh>
#include <dune/common/exceptions.hh>
#include <dune/common/fvector.hh>
using Dune::FieldVector;
......@@ -49,8 +52,7 @@ int main()
std::cout << std::endl;
} catch (Dune::Exception& e) {
std::cerr << e << std::endl;
return 1;
throw;
} catch (...) {
std::cerr << "Generic exception!" << std::endl;
return 2;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment