Vault  4.1
Public Member Functions | Static Public Member Functions
VSystemError Class Reference

VSystemError captures the current system error code and the corresponding error message text. More...

#include <vexception.h>

List of all members.

Public Member Functions

 VSystemError ()
 The default constructor captures the current system error code and its error message.
 VSystemError (int errorCode)
 This constructor lets you supply the error code, and the error message will be obtained automatically.
 VSystemError (int errorCode, const VString &errorMessage)
 This constructor lets you supply both the error code and the error message.
int getErrorCode () const
 Returns the stored error code.
VString getErrorMessage () const
 Returns the stored error message.
bool isLikePosixError (int posixErrorCode) const
 Returns true if the internal error code is equivalent to the specified POSIX error code constant, for the platform.

Static Public Member Functions

static VSystemError getSocketError ()
 This static API builds a system error object by getting the current socket error code.

Detailed Description

VSystemError captures the current system error code and the corresponding error message text.

A static API is provided to specifically capture the current socket error code. Alternate constructors let you supply an error code and an error message.

You can supply one of these objects to a VException as a convenient way to get the system error code and text represented in the exception text, appended in a standard way to the exception error message text that you provide. This allows more easily throwing exceptions that capture the system error code and message in a platform-independent way without having to carefully construct an exception error string that includes all of it explicitly.

Here's precisely what I mean in the terminology here:

Definition at line 141 of file vexception.h.


Constructor & Destructor Documentation

VSystemError::VSystemError ( )

The default constructor captures the current system error code and its error message.

This is usually sufficient to supply to a thrown VException.

Definition at line 22 of file vexception.cpp.

VSystemError::VSystemError ( int  errorCode)

This constructor lets you supply the error code, and the error message will be obtained automatically.

This can be useful if an API returns a specific error code and the current system error code is not relevant.

Parameters:
errorCodean error code to store; the OS will be asked to obtain the relevant error message for that error code

Definition at line 28 of file vexception.cpp.

VSystemError::VSystemError ( int  errorCode,
const VString errorMessage 
)

This constructor lets you supply both the error code and the error message.

The OS will not be asked to form the error message. An example from the Unix socket implementation is ::getaddrinfo() which doesn't use ::strerror() for obtaining an error message.

Parameters:
errorCodean error code to store
errorMessagean error message to store

Definition at line 34 of file vexception.cpp.


Member Function Documentation

VSystemError VSystemError::getSocketError ( ) [static]

This static API builds a system error object by getting the current socket error code.

On Windows current socket error code is separate from the current system error code, so for socket-related APIs on any platform you should use this to get a system error object.

Returns:
a VSystemError containing the current socket error code and message

Definition at line 18 of file vexception.cpp.

References VSystemError().

int VSystemError::getErrorCode ( ) const [inline]

Returns the stored error code.

The numeric values for error codes are generally very platform-specific.

Returns:
obvious

Definition at line 181 of file vexception.h.

VString VSystemError::getErrorMessage ( ) const [inline]

Returns the stored error message.

For system and socket error codes, this string will normally have been obtained by asking the OS to form a string that corresponds to the stored error code.

Returns:
obvious

Definition at line 188 of file vexception.h.

bool VSystemError::isLikePosixError ( int  posixErrorCode) const [inline]

Returns true if the internal error code is equivalent to the specified POSIX error code constant, for the platform.

For example, on Windows an interrupted call would be the constant WSAEINTR, which is equivalent -- but not the same number -- as the POSIX constant EINTR; you could call isPosixError(EINTR) to test for that condition on either platform. You generally just throw an exception when you encounter an error, but in a few cases you need to decide which corrective action or which specific exception to throw, based on the exact error code.

Definition at line 198 of file vexception.h.


The documentation for this class was generated from the following files:

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.