1
2
3
4
5
6 namespace System
7 {
8 public const int EFAIL = 1;
9 public const int EBADF = 2;
10 public const int EPARAM = 3;
11 public const int EMEMORYACCESS = 4;
12 public const int ENOTFOUND = 5;
13 public const int EALREADYEXISTS = 6;
14 public const int ELIMITEXCEEDED = 7;
15 public const int ENOCHILD = 8;
16 public const int EHOST = 9;
17 public const int EPERMISSION = 10;
18 public const int ESOCKET = 11;
19
20 public class SystemError : Exception
21 {
22 public nothrow SystemError(int errorCode_, const string& message_) : base(message_), errorCode(errorCode_)
23 {
24 }
25 public int errorCode;
26 }
27
28 public SystemError GetSystemError()
29 {
30 int errorCode;
31 UniquePtr<byte> buffer(cast<byte*>(MemAlloc(4096)));
32 if (get_system_error(&errorCode, buffer.Get(), 4096) == 0)
33 {
34 string errorMessage;
35 byte* p = buffer.Get();
36 while (*p != 0u)
37 {
38 errorMessage.Append(cast<char>(*p));
39 ++p;
40 }
41 return SystemError(errorCode, errorMessage);
42 }
43 return SystemError(EFAIL, "could not get system error");
44 }
45
46 public void ThrowSystemError()
47 {
48 throw GetSystemError();
49 }
50 }