blob: 044e16d6bce9296afed244873ef6daa08fa61d82 [file] [log] [blame]
Mark Slee8d7e1f62006-06-07 06:48:56 +00001#ifndef T_TRANSPORT_EXCEPTION_H
2#define T_TRANSPORT_EXCEPTION_H
3
4#include <string>
5
6/**
7 * Error codes for the various types of exceptions.
8 */
9enum TTransportExceptionType {
10 TTX_UNKNOWN = 0,
11 TTX_NOT_OPEN = 1,
12 TTX_TIMED_OUT = 2,
13};
14
15/**
16 * Class to encapsulate all the possible types of transport errors that may
17 * occur in various transport systems. This provides a sort of generic
18 * wrapper around the shitty UNIX E_ error codes that lets a common code
19 * base of error handling to be used for various types of transports, i.e.
20 * pipes etc.
21 *
22 * @author Mark Slee <mcslee@facebook.com>
23 */
24class TTransportException {
25 public:
26 TTransportException() :
27 type_(TTX_UNKNOWN), message_() {}
28
29 TTransportException(TTransportExceptionType type) :
30 type_(type), message_() {}
31
32 TTransportException(std::string message) :
33 type_(TTX_UNKNOWN), message_(message) {}
34
35 TTransportException(TTransportExceptionType type, std::string message) :
36 type_(type), message_(message) {}
37
38 ~TTransportException() {}
39
40 /**
41 * Returns an error code that provides information about the type of error
42 * that has occurred.
43 *
44 * @return Error code
45 */
46 TTransportExceptionType getType() { return type_; }
47
48 /**
49 * Returns an informative message about what caused this error.
50 *
51 * @return Error string
52 */
53 const std::string& getMessage() { return message_; }
54
55 protected:
56 /** Error code */
57 TTransportExceptionType type_;
58
59 /** Description */
60 std::string message_;
61};
62
63#endif