#include <Error.h>
Inheritance diagram for GNE::Error:
Public Types | |
NoError = 0 | |
ProtocolViolation | |
GNETheirVersionLow | |
GNETheirVersionHigh | |
WrongGame | |
UserVersionMismatch | |
CouldNotOpenSocket | |
ConnectionTimeOut | |
ConnectionAborted | |
ConnectionRefused | |
ConnectionDropped | |
SyncConnectionReleased | |
ExitNoticeReceived | |
Read | |
Write | |
UnknownPacket | |
PacketTypeMismatch | |
DuplicateObjectId | |
UnknownObjectId | |
InvalidObjectPacket | |
InvalidCreationPacketType | |
BufferUnderflow | |
BufferOverflow | |
InvalidBufferPosition | |
InvalidBufferLimit | |
OtherGNELevelError | |
OtherLowLevelError | |
User | |
Useful for user-defined classes that inherit from Error. | |
enum | ErrorCode { NoError = 0, ProtocolViolation, GNETheirVersionLow, GNETheirVersionHigh, WrongGame, UserVersionMismatch, CouldNotOpenSocket, ConnectionTimeOut, ConnectionAborted, ConnectionRefused, ConnectionDropped, SyncConnectionReleased, ExitNoticeReceived, Read, Write, UnknownPacket, PacketTypeMismatch, DuplicateObjectId, UnknownObjectId, InvalidObjectPacket, InvalidCreationPacketType, BufferUnderflow, BufferOverflow, InvalidBufferPosition, InvalidBufferLimit, OtherGNELevelError, OtherLowLevelError, User } |
An enum describing connection failure type. More... | |
Public Member Functions | |
Error (ErrorCode ec=NoError) | |
Create a new object representing a certain error, given by the passed ErrorCode. | |
ErrorCode | getCode () const |
Returns the error code for this error. | |
const void | setCode (ErrorCode newCode) |
Sets the error code for this error, useful after a call to createLowLevelError() to specify a more appropriate high-level error code. | |
virtual std::string | toString () const |
Returns a string description of this error. | |
operator bool () const | |
Returns getCode() != NoError, a handy shortcut so you can test for error by if (error). | |
bool | operator== (const ErrorCode &rhs) const |
A handy shortcut for (error.getCode() == rhs). |
Objects of type Error are not thread safe. This is usually OK since Error objects are not typically shared by threads.
If you want to define your own classes from Error, feel free to do so. This may be useful if you want to throw Errors during readPacket or writePacket. If you inherit from Error, unless one of the current error codes apply, you should give the Error a code of User and overload the toString method to provide your own error description.
An enum describing connection failure type.
User | Useful for user-defined classes that inherit from Error. |
GNE::Error::Error | ( | ErrorCode | ec = NoError |
) |
Create a new object representing a certain error, given by the passed ErrorCode.
If no error code is passed, NoError is assumed.
bool GNE::Error::operator== | ( | const ErrorCode & | rhs | ) | const |
A handy shortcut for (error.getCode() == rhs).
rhs | an errorCode to test with. |
const void GNE::Error::setCode | ( | ErrorCode | newCode | ) |
Sets the error code for this error, useful after a call to createLowLevelError() to specify a more appropriate high-level error code.
The Error object still retains the low-level specific error information.
std::string GNE::Error::toString | ( | ) | const [virtual] |
Returns a string description of this error.
When possible, the string is "programmer-friendly," so you will probably want to only use this to write a debug message or out to a log, and tell the user more about the error.
Reimplemented in GNE::UserError, GNE::LowLevelError, GNE::WrongGame, GNE::UnknownPacket, and GNE::ProtocolViolation.