DCL 3.7.4
Loading...
Searching...
No Matches
SysError Class Reference

#include <Exception.h>

Inheritance diagram for SysError:
Exception Object DllException IOException

Public Member Functions

 SysError (Exception *_cause=NULL)
 SysError (uint32_t _errorNo)
uint32_t errorNo () const
virtual String toString () const
Public Member Functions inherited from Exception
 Exception (Exception *_cause=NULL)
const Exceptioncause () const
String toStringAll () const
virtual void destroy ()
Public Member Functions inherited from Object
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Additional Inherited Members

Protected Member Functions inherited from Exception
virtual ~Exception ()
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()
Protected Attributes inherited from Exception
Exception__cause

Detailed Description

Definition at line 62 of file Exception.h.

Constructor & Destructor Documentation

◆ SysError() [1/2]

SysError::SysError ( Exception * _cause = NULL)

◆ SysError() [2/2]

SysError::SysError ( uint32_t _errorNo)

Definition at line 97 of file Exception.cpp.

98{
99 __errorNo = _errorNo;
100}

Member Function Documentation

◆ errorNo()

uint32_t SysError::errorNo ( ) const
inline

Definition at line 78 of file Exception.h.

78{ return __errorNo; }

◆ toString()

String SysError::toString ( ) const
virtual

Reimplemented from Exception.

Reimplemented in DllException, and IOException.

Definition at line 102 of file Exception.cpp.

103{
104 StringBuilder sb;
105 if (__errorNo & DCL_ERROR_MASK) {
106 ;
107 }
108#ifdef __WINNT__
109 else if (__errorNo & WINAPI_ERROR_MASK) {
110 uint32_t _errorNo = __errorNo & ERROR_VALUE_MASK;
111 wchar_t* msg = NULL;
112 DWORD dwLength = ::FormatMessageW(
113 FORMAT_MESSAGE_ALLOCATE_BUFFER |
114 FORMAT_MESSAGE_FROM_SYSTEM |
115 FORMAT_MESSAGE_IGNORE_INSERTS,
116 NULL,
117 _errorNo,
118 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
119 (LPWSTR) &msg,
120 0,
121 NULL
122 );
123
124 if (dwLength > 0) {
125 for ( ; dwLength; dwLength--)
126 if (!(msg[dwLength - 1] == L'\r' || msg[dwLength - 1] == L'\n'))
127 break;
128
129 sb.assign(msg, dwLength);
130 LocalFree(msg);
131
132 sb += L" (ERROR=";
133 sb += UInt32::toString(_errorNo, 10);
134 sb += L")";
135 }
136 else
137 sb = L"::FormatMessage Fail!";
138 }
139#endif
140 else {
141 // errno
142 uint32_t _errorNo = __errorNo & ERROR_VALUE_MASK;
143
144#ifdef __WINNT__
145 CharBuffer* buf = CharBuffer::create(256);
146 if (_wcserror_s(buf->data(), buf->__allocLength, __errorNo))
147 buf->release();
148 else {
149 buf->__dataLength = String::length(buf->data());
150 __DCL_ASSERT(buf->data()[buf->__dataLength] == __T('\0'));
151 sb.assign(buf);
152 buf->release();
153 }
154#else
155 // UNIX
156 String s;
157 if (__strerror(s, _errorNo) == 0)
158 sb += s;
159#endif
160 sb += L" (errno=" + UInt32::toString(_errorNo, 10) + L")";
161 }
162 return sb;
163}
DCLCAPI int __strerror(String &_r, int _errnum)
Definition _string.cpp:21
#define NULL
Definition Config.h:312
#define DCL_ERROR_MASK
Definition Exception.h:71
#define WINAPI_ERROR_MASK
Definition Exception.h:70
#define ERROR_VALUE_MASK
Definition Exception.h:68
#define __DCL_ASSERT(expr)
Definition Object.h:394
#define __T(str)
Definition Object.h:60
String toString(unsigned _base=10) const
Definition Numeric.inl:105

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