Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include "StreamArguments.h" 13 : 14 : #include <exception> 15 : #include <sstream> 16 : 17 : /** 18 : * Provides a way for users to bail out of the current solve. 19 : */ 20 : class MooseException : public std::exception 21 : { 22 : public: 23 : /** 24 : * @param message The message to display 25 : */ 26 323 : MooseException(std::string message) : _message(message) {} 27 : 28 : /** 29 : * Set an explicit default constructor to avoid the variadic template constructor 30 : * below catch the copy construction case. 31 : */ 32 : MooseException(const MooseException &) = default; 33 : 34 : /** 35 : * @param args List of arguments that gets stringified and concatenated to form the message to 36 : * display 37 : */ 38 : template <typename... Args> 39 410 : explicit MooseException(Args &&... args) 40 410 : { 41 410 : std::ostringstream ss; 42 410 : streamArguments(ss, args...); 43 410 : _message = ss.str(); 44 410 : } 45 : 46 : /** 47 : * For some reason, on GCC 4.6.3, I get 'error: looser throw 48 : * specifier' when deriving from std::exception unless I declare 49 : * that the destructor *won't* throw by adding the throw() 50 : * specification. Clang doesn't seem to care about this line of 51 : * code. 52 : */ 53 717 : ~MooseException() throw() {} 54 : 55 : /** 56 : * Get out the error message. 57 : * 58 : * Satisfies the interface of std::exception 59 : */ 60 412 : virtual const char * what() const throw() { return _message.c_str(); } 61 : 62 : protected: 63 : std::string _message; 64 : };