/
exceptions.h
128 lines (115 loc) · 3.27 KB
/
exceptions.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2004 Aldratech Ltd. See the LICENSE file for licensing information.
/*
This file is part of hessiancpp.
hessiancpp is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
hessiancpp 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with hessiancpp; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HESSIAN_EXCEPTIONS_H
#define HESSIAN_EXCEPTIONS_H
#include <exception>
#include <string>
#include "wrappers.h"
#ifdef WIN32
#pragma warning(disable:4290)
#endif
// using namespace hessian::wrappers;
namespace std {}
namespace hessian {
namespace exceptions {
using namespace std;
///io_exception class.
class io_exception : public exception {
public:
///Constructor with error message.
explicit io_exception(const string& what): _message(what) {
}
///Destructor.
virtual ~io_exception() throw() {
}
///Get error message.
const char* what() const throw() {
return _message.c_str();
}
///Re-throw.
virtual void raise() const {
throw *this;
}
protected:
string _message;
};
///fault_exception class representing a Hessian Fault.
class fault_exception : public exception {
public:
///Constructor with code and message.
fault_exception(const wstring& code,
const wstring& message)
: _code(code), _message(message)
{
string c=wrappers::String::to_string(_code);
string m=wrappers::String::to_string(_message);
_what = string("code ").append(c)
.append(", message ")
.append(m);
}
fault_exception(const string& code,
const string& message
) :
_code(wrappers::String::to_wstring(code)),
_message(wrappers::String::to_wstring(message))
{
_what = string("code ").append(code)
.append(", message ")
.append(message);
}
///Constructor from Fault.
fault_exception(const wrappers::Fault& fault) :
_code(fault.wcode()), _message(fault.wmessage())
{
string c=wrappers::String::to_string(_code);
string m=wrappers::String::to_string(_message);
_what = string("code ").append(c)
.append(", message ")
.append(m);
}
///Destructor.
virtual ~fault_exception() throw() {
}
///Get error message with code and message.
const char* what() const throw() {
return _what.c_str();
}
///Re-throw.
virtual void raise() const {
throw *this;
}
///Get the Fault code.
wstring wcode() const throw() {
return _code;
}
wstring wmessage() const throw() {
return _message;
}
string code() const throw() {
return wrappers::String::to_string(_code);
}
///Get the Fault message.
string message() const throw() {
return wrappers::String::to_string(_message);
}
protected:
wstring _code;
wstring _message;
string _what;
};
}
}
#endif