ITAException.h 1.85 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2 3 4 5
 * ----------------------------------------------------------------
 *
 *		ITA core libs
 *		(c) Copyright Institute of Technical Acoustics (ITA)
6
 *		RWTH Aachen University, Germany, 2015-2019
7 8 9 10 11 12 13 14 15 16 17
 *
 * ----------------------------------------------------------------
 *				    ____  __________  _______
 *				   //  / //__   ___/ //  _   |
 *				  //  /    //  /    //  /_|  |
 *				 //  /    //  /    //  ___   |
 *				//__/    //__/    //__/   |__|
 *
 * ----------------------------------------------------------------
 *
 */
Jonas Stienen's avatar
Jonas Stienen committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

#ifndef INCLUDE_WATCHER_ITA_EXCEPTION
#define INCLUDE_WATCHER_ITA_EXCEPTION

// ITABase
#include <ITABaseDefinitions.h>

// STL
#include <ostream>
#include <string>

//! Base class for exceptions
class ITA_BASE_API ITAException
{
public:
	//! Error types
	enum
	{
		UNKNOWN = 1,		//!< Unspecified
		OUT_OF_MEMORY,		//!< Out of memory
		INVALID_PARAMETER,	//!< Invalid parameter
		MODAL_EXCEPTION,
		IO_ERROR,
		NOT_IMPLEMENTED,
		FILE_NOT_FOUND,
		PARSE_ERROR,
		SYNTAX_ERROR,
		CONFIG_ERROR,
46
		NETWORK_ERROR,
Jonas Stienen's avatar
Jonas Stienen committed
47 48 49
		LAST,
	};

50
	ITAException( int uiErrorcode = UNKNOWN, std::string sModule = "", std::string sReason = "" );
Jonas Stienen's avatar
Jonas Stienen committed
51 52 53 54 55 56 57 58 59 60 61 62
	inline virtual ~ITAException() {};

	std::string ToString() const;

	int iErrorCode;		//!< Error code
	std::string sModule;	//!< Module name
	std::string sReason;	//!< Versatile reason
};

// Helper macros
#define ITA_EXCEPT0( TYPE ) throw ITAException( ITAException::TYPE, __FUNCTION__ );
#define ITA_EXCEPT1( TYPE, REASON ) throw ITAException( ITAException::TYPE, __FUNCTION__, REASON );
63
#define ITA_EXCEPT_INVALID_PARAMETER( REASON ) throw ITAException( ITAException::INVALID_PARAMETER, __FUNCTION__, REASON );
64
#define ITA_EXCEPT_NOT_IMPLEMENTED  throw ITAException( ITAException::NOT_IMPLEMENTED, __FUNCTION__ );
Jonas Stienen's avatar
Jonas Stienen committed
65 66

//! STL stream output operator
67
ITA_BASE_API std::ostream& operator<<( std::ostream& os, const ITAException& ex );
Jonas Stienen's avatar
Jonas Stienen committed
68 69

#endif