Blame view

src/Common/AMDA_exception.hh 1.24 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
46
47
48
49
50
51
52
/**
 * AMDA_exception.hh
 *
 *  Created on: 16 oct. 2012
 *      Author: AKKA IS
 */

#ifndef AMDA_EXCEPTION_HH_
#define AMDA_EXCEPTION_HH_

#include <string>

#include "log4cxx/logger.h"

#include "DicError.hh"
#include "boost/exception/all.hpp"

/**
 * facility to throw an exception with log
 */
#define ERROR_EXCEPTION(msg)  { LOG4CXX_ERROR( gLogger, msg); \
    std::stringstream oss; oss << msg; \
    BOOST_THROW_EXCEPTION( exception() << ex_msg(oss.str())); \
    }

namespace AMDA {
/**
 * @brief Store, error number return by AMDA application, @see DicError.hh
 */
  typedef boost::error_info<struct tag_errno_code,int> errno_code;

/**
 * @brief definition exception AMDA
 */
struct AMDA_exception: virtual std::exception, virtual boost::exception {
};

typedef boost::error_info<struct tag_errno_code,int> errno_code;
typedef boost::error_info<struct tag_ex_msg,std::string> ex_msg;

inline std::string traitException(int &result, AMDA::AMDA_exception & e) {
	if (int const* res = boost::get_error_info<AMDA::errno_code>(e)) {
		result = *res;
	} else {
		result = AMDA_ERROR_UNKNOWN;
	}
	return boost::diagnostic_information(e);//error of parser Eclipse because e may be an boost or an std exception
}

} /* namespace AMDA */

#endif /* AMDA_EXCEPTION_HH_ */