2017-12-12 14:04:28 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: extras/Hadrons/Exceptions.hpp
|
|
|
|
|
2017-12-26 13:16:47 +00:00
|
|
|
Copyright (C) 2015-2018
|
2017-12-12 14:04:28 +00:00
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
|
|
|
|
This program 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 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
|
|
|
|
|
|
|
#ifndef Hadrons_Exceptions_hpp_
|
|
|
|
#define Hadrons_Exceptions_hpp_
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#ifndef Hadrons_Global_hpp_
|
|
|
|
#include <Grid/Hadrons/Global.hpp>
|
|
|
|
#endif
|
|
|
|
|
2018-04-25 16:49:14 +01:00
|
|
|
#define HADRONS_SRC_LOC std::string(__FUNCTION__) + " at " \
|
|
|
|
+ std::string(__FILE__) + ":" + std::to_string(__LINE__)
|
|
|
|
#define HADRONS_ERROR(exc, msg)\
|
|
|
|
throw(Exceptions::exc(msg, HADRONS_SRC_LOC));
|
2017-12-12 14:04:28 +00:00
|
|
|
|
2018-07-26 16:47:25 +01:00
|
|
|
#define HADRONS_ERROR_REF(exc, msg, address)\
|
|
|
|
throw(Exceptions::exc(msg, HADRONS_SRC_LOC, address));
|
|
|
|
|
2017-12-12 14:04:28 +00:00
|
|
|
#define DECL_EXC(name, base) \
|
|
|
|
class name: public base\
|
|
|
|
{\
|
|
|
|
public:\
|
|
|
|
name(std::string msg, std::string loc);\
|
|
|
|
}
|
|
|
|
|
2018-07-26 16:47:25 +01:00
|
|
|
#define DECL_EXC_REF(name, base) \
|
|
|
|
class name: public base\
|
|
|
|
{\
|
|
|
|
public:\
|
|
|
|
name(std::string msg, std::string loc, const unsigned int address);\
|
|
|
|
}
|
|
|
|
|
2017-12-12 14:04:28 +00:00
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
namespace Exceptions
|
|
|
|
{
|
|
|
|
// logic errors
|
|
|
|
DECL_EXC(Logic, std::logic_error);
|
|
|
|
DECL_EXC(Definition, Logic);
|
|
|
|
DECL_EXC(Implementation, Logic);
|
|
|
|
DECL_EXC(Range, Logic);
|
|
|
|
DECL_EXC(Size, Logic);
|
2018-04-23 12:48:00 +01:00
|
|
|
|
2017-12-12 14:04:28 +00:00
|
|
|
// runtime errors
|
|
|
|
DECL_EXC(Runtime, std::runtime_error);
|
|
|
|
DECL_EXC(Argument, Runtime);
|
|
|
|
DECL_EXC(Io, Runtime);
|
|
|
|
DECL_EXC(Memory, Runtime);
|
|
|
|
DECL_EXC(Parsing, Runtime);
|
|
|
|
DECL_EXC(Program, Runtime);
|
|
|
|
DECL_EXC(System, Runtime);
|
2018-04-23 12:48:00 +01:00
|
|
|
|
2018-07-26 16:47:25 +01:00
|
|
|
// virtual machine errors
|
|
|
|
class RuntimeRef: public Runtime
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RuntimeRef(std::string msg, std::string loc, const unsigned int address)
|
|
|
|
: Runtime(msg, loc), address_(address)
|
|
|
|
{}
|
|
|
|
unsigned int getAddress(void) const
|
|
|
|
{
|
|
|
|
return address_;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
unsigned int address_;
|
|
|
|
};
|
|
|
|
|
|
|
|
DECL_EXC_REF(ObjectDefinition, RuntimeRef);
|
|
|
|
|
2018-04-23 12:48:00 +01:00
|
|
|
// abort functions
|
|
|
|
void abort(const std::exception& e);
|
2017-12-12 14:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
|
|
|
#endif // Hadrons_Exceptions_hpp_
|