Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::Error Class Reference
[Mid-Level API]

#include <Error.h>

Inheritance diagram for GNE::Error:

GNE::BufferError GNE::LowLevelError GNE::PacketTypeMismatch GNE::ProtocolViolation GNE::UnknownPacket GNE::UserError GNE::UserVersionMismatch GNE::WrongGame List of all members.

Public Types

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).


Detailed Description

This class resembles some sort of error in GNE, with the ability to obtain a textual description of the error. 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.

See also:
Packet::readPacket

Packet::writePacket


Member Enumeration Documentation

enum GNE::Error::ErrorCode
 

An enum describing connection failure type.

Enumeration values:
User  Useful for user-defined classes that inherit from Error.


Constructor & Destructor Documentation

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.


Member Function Documentation

bool GNE::Error::operator== const ErrorCode rhs  )  const
 

A handy shortcut for (error.getCode() == rhs).

Parameters:
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.


The documentation for this class was generated from the following files:
Generated on Fri Aug 22 13:40:06 2003 for GNE by doxygen1.3