![]() |
Vault
4.1
|
VSystemError captures the current system error code and the corresponding error message text. More...
#include <vexception.h>
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. |
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.
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.
errorCode | an 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.
errorCode | an error code to store |
errorMessage | an error message to store |
Definition at line 34 of file vexception.cpp.
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.
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.
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.
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.