VAException.cpp 2.44 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 16 17 18
 */

#include <VAException.h>

#include <sstream>

CVAException::CVAException()
19 20 21
	: m_iErrorCode( UNSPECIFIED )
{
}
Jonas Stienen's avatar
Jonas Stienen committed
22

23 24 25 26 27
CVAException::CVAException( const int iErrorCode, const std::string& sErrorMessage )
	: m_iErrorCode( iErrorCode )
	, m_sErrorMessage( sErrorMessage )
{
}
Jonas Stienen's avatar
Jonas Stienen committed
28 29 30 31 32 33 34 35 36

CVAException::~CVAException() {}

int CVAException::GetErrorCode() const { return m_iErrorCode; }

std::string CVAException::GetErrorMessage() const { return m_sErrorMessage; }

std::string CVAException::ToString() const {
	std::stringstream ss;
37 38

	switch( m_iErrorCode ) {
Jonas Stienen's avatar
Jonas Stienen committed
39
	case MODAL_ERROR:
40
		if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
41 42 43 44 45 46
			ss << "Modal error: " << m_sErrorMessage << " (error code " << m_iErrorCode << ")";
		else
			ss << "Modal error: " << m_sErrorMessage;
		break;

	case NETWORK_ERROR:
47
		if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
48 49 50 51 52 53
			ss << "Network error: " << m_sErrorMessage << " (error code " << m_iErrorCode << ")";
		else
			ss << "Network error: " << m_sErrorMessage;
		break;

	case PROTOCOL_ERROR:
54
		if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
55 56 57 58 59
			ss << "Network protocol error: " << m_sErrorMessage << " (error code " << m_iErrorCode << ")";
		else
			ss << "Network protocol error: " << m_sErrorMessage;
		break;

60
		// Alle anderen bekannten Fehler
Jonas Stienen's avatar
Jonas Stienen committed
61 62 63 64 65
	case NOT_IMPLEMENTED:
	case INVALID_PARAMETER:
	case INVALID_ID:
	case RESOURCE_IN_USE:
	case FILE_NOT_FOUND:
66
		if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
67 68 69 70 71 72
			ss << m_sErrorMessage << " (error code " << m_iErrorCode << ")";
		else
			ss << m_sErrorMessage;
		break;

	default:
73 74
		if( m_sErrorMessage.empty() ) {
			if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
75 76 77
				ss << "An unspecified error occured (error code " << m_iErrorCode << ")";
			else
				ss << "An unspecified error occured";
78 79 80
		}
		else {
			if( m_iErrorCode != 0 )
Jonas Stienen's avatar
Jonas Stienen committed
81 82 83 84 85 86 87 88 89 90
				ss << m_sErrorMessage << " (error code " << m_iErrorCode << ")";
			else
				ss << m_sErrorMessage;
		}
		break;
	}

	return ss.str();
}

91
std::ostream& operator<<( std::ostream& os, const CVAException& ex ) {
Jonas Stienen's avatar
Jonas Stienen committed
92 93
	return os << ex.ToString();
}