VAException.h 2.5 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
3
 *
4 5 6 7 8 9
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
 *       VVV  VVV     AAA        Copyright 2015-2017
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
Jonas Stienen's avatar
Jonas Stienen committed
10
 *
11
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
12 13
 */

14 15
#ifndef IW_VABASE_EXCEPTION
#define IW_VABASE_EXCEPTION
Jonas Stienen's avatar
Jonas Stienen committed
16 17 18 19 20 21 22 23 24 25 26

#include <VABaseDefinitions.h>
#include <ostream>
#include <string>

//! Base class for exceptions
/**
 * This is the exception base class for all VA software components.
 * Exceptions are defined by an error code and an error message.
 */

27 28
class VABASE_API CVAException
{
Jonas Stienen's avatar
Jonas Stienen committed
29 30
public:
	//! Error codes
31 32
	enum ErrorCode 
	{
Jonas Stienen's avatar
Jonas Stienen committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
		UNSPECIFIED = 0,		//!< An error that is not specified in detail
		INVALID_PARAMETER = 1,	//!< A parameter provided is invalid
		INVALID_ID = 2,			//!< An identifier (ID) provided is invalid
		MODAL_ERROR = 3,		//!< A modal error occured
		RESOURCE_IN_USE = 4,	//!< The resource is in use
		FILE_NOT_FOUND = 5,		//!< A file was not found
		NETWORK_ERROR = 6,		//!< A networking error occured
		PROTOCOL_ERROR = 7,		//!< Behaviour violates the protocol specification
		NOT_IMPLEMENTED = 8,	//!< A specific behaviour is not implemented by a component
	};

	//! Default constructor
	CVAException();

	//! Initialization constructor
48
	CVAException( int iErrorCode, const std::string& sErrorMessage = "" );
Jonas Stienen's avatar
Jonas Stienen committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

	//! Destructor
	virtual ~CVAException();

	//! Returns the error code
	int GetErrorCode() const;

	//! Returns the error message
	std::string GetErrorMessage() const;

	//! Return a string representation of the exception
	std::string ToString() const;

protected:
	int m_iErrorCode;
	std::string m_sErrorMessage;
};

//! Macro for throwing exceptions
#define VA_EXCEPT0(ERRRORCODE) { throw CVAException( (CVAException::ERRRORCODE) ); }
#define VA_EXCEPT1(ERRRORMSG) { throw CVAException(CVAException::UNSPECIFIED, (ERRRORMSG) ); }
#define VA_EXCEPT2(ERRORCODE, ERRRORMSG) { throw CVAException( (CVAException::ERRORCODE) , (ERRRORMSG) ); }
71
#define VA_EXCEPT_NOT_IMPLEMENTED { throw CVAException( (CVAException::NOT_IMPLEMENTED) , "Not implemented" ); }
Jonas Stienen's avatar
Jonas Stienen committed
72 73

//! STL stream output operator
74
VABASE_API std::ostream& operator<<( std::ostream& os, const CVAException& ex );
Jonas Stienen's avatar
Jonas Stienen committed
75

76
#endif // IW_VABASE_EXCEPTION