2011-10-07 03:54:25 -05:00
|
|
|
/*
|
2013-08-28 06:36:46 -05:00
|
|
|
Copyright 2013 Andreas Lauser
|
2013-01-29 06:17:01 -06:00
|
|
|
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2009, 2010 Statoil ASA.
|
2011-10-07 03:54:25 -05:00
|
|
|
|
2013-01-29 06:17:01 -06:00
|
|
|
This file is part of the Open Porous Media project (OPM).
|
2011-10-07 03:54:25 -05:00
|
|
|
|
2013-01-29 06:17:01 -06:00
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2011-10-07 03:54:25 -05:00
|
|
|
|
2013-01-29 06:17:01 -06:00
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2011-10-07 03:54:25 -05:00
|
|
|
|
2013-01-29 06:17:01 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-07 03:54:25 -05:00
|
|
|
*/
|
2013-08-28 06:36:46 -05:00
|
|
|
#ifndef OPM_ERRORMACROS_HPP
|
|
|
|
#define OPM_ERRORMACROS_HPP
|
2011-10-07 03:54:25 -05:00
|
|
|
|
2013-08-28 06:36:46 -05:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2011-10-07 03:54:25 -05:00
|
|
|
#include <exception>
|
2013-08-28 06:36:46 -05:00
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
// macros for reporting to stderr
|
|
|
|
#ifdef OPM_VERBOSE // Verbose mode
|
|
|
|
# include <iostream>
|
|
|
|
# define OPM_REPORT do { std::cerr << "[" << __FILE__ << ":" << __LINE__ << "] " } while (false)
|
|
|
|
# define OPM_MESSAGE(x) do { OPM_REPORT; std::cerr << x << "\n"; } while (false)
|
|
|
|
# define OPM_MESSAGE_IF(cond, m) do {if(cond) OPM_MESSAGE(m);} while (false)
|
|
|
|
#else // non-verbose mode (default)
|
|
|
|
# define OPM_REPORT do {} while (false)
|
|
|
|
# define OPM_MESSAGE(x) do {} while (false)
|
|
|
|
# define OPM_MESSAGE_IF(cond, m) do {} while (false)
|
2011-10-07 03:54:25 -05:00
|
|
|
#endif
|
|
|
|
|
2013-08-28 06:36:46 -05:00
|
|
|
// Macro to throw an exception. NOTE: For this macro to work, the
|
|
|
|
// exception class must exhibit a constructor with the signature
|
|
|
|
// (const std::string &message). Since this condition is not fulfilled
|
|
|
|
// for the std::exception, you should use this macro with some
|
|
|
|
// exception class derived from either std::logic_error or
|
|
|
|
// std::runtime_error.
|
|
|
|
//
|
|
|
|
// Usage: OPM_THROW(ExceptionClass, "Error message " << value);
|
2013-09-10 18:03:25 -05:00
|
|
|
#define OPM_THROW(Exception, message) \
|
2013-08-28 06:36:46 -05:00
|
|
|
do { \
|
2013-09-10 18:03:25 -05:00
|
|
|
std::ostringstream oss__; \
|
|
|
|
oss__ << "[" << __FILE__ << ":" << __LINE__ << "] " << message; \
|
2013-08-28 06:36:46 -05:00
|
|
|
OPM_MESSAGE(message); \
|
2013-09-10 18:03:25 -05:00
|
|
|
throw Exception(oss__.str()); \
|
2013-08-28 06:36:46 -05:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
// throw an exception if a condition is true
|
2013-09-06 06:23:18 -05:00
|
|
|
#define OPM_ERROR_IF(condition, message) do {if(condition){ OPM_THROW(std::logic_error, message);}} while(false)
|
2013-08-28 06:36:46 -05:00
|
|
|
|
|
|
|
#endif // OPM_ERRORMACROS_HPP
|