DCL 4.0
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__pCause

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 98 of file Exception.cpp.

99{
100 __errorNo = _errorNo;
101}

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 103 of file Exception.cpp.

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

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