1 using System;
2
3 namespace cmsx.kernel
4 {
5 public const int EFAIL = 1;
6 public const int EBADF = 2;
7 public const int EMEM = 3;
8 public const int ERLIMITEXCEEDED = 4;
9 public const int EINVAL = 5;
10 public const int ENOTSUPPORTED = 6;
11 public const int EIO = 7;
12 public const int EPERM = 8;
13 public const int EEXIST = 9;
14 public const int ENOENT = 10;
15 public const int ERANGE = 11;
16
17 public string ErrorCodeStr(int errorCode)
18 {
19 switch (errorCode)
20 {
21 case EFAIL: return "EFAIL";
22 case EBADF: return "EBADF";
23 case EMEM: return "EMEM";
24 case ERLIMITEXCEEDED: return "ERLIMITEXCEEDED";
25 case EINVAL: return "EINVAL";
26 case ENOTSUPPORTED: return "ENOTSUPPORTED";
27 case EIO: return "EIO";
28 case EPERM: return "EPERM";
29 case EEXIST: return "EEXIST";
30 case ENOENT: return "ENOENT";
31 case ERANGE: return "ERANGE";
32 }
33 return "";
34 }
35
36 public string ErrorMsg(int errorCode)
37 {
38 switch (errorCode)
39 {
40 case EFAIL: return "Host system failure";
41 case EBADF: return "Bad file descriptor";
42 case EMEM: return "Memory error";
43 case ERLIMITEXCEEDED: return "Resource limit exceeeded";
44 case EINVAL: return "Invalid argument";
45 case ENOTSUPPORTED: return "Operation not supported";
46 case EIO: return "I/O error";
47 case EPERM: return "Permission denied";
48 case EEXIST: return "Path exists";
49 case ENOENT: return "No such file or directory";
50 case ERANGE: return "Result too large";
51 }
52 return "";
53 }
54
55 public class SystemError : Exception
56 {
57 public nothrow SystemError(int errorCode_, const string& message_) :
58 base(ErrorCodeStr(errorCode_) + "(" + ToString(errorCode_) + "): " + ErrorMsg(errorCode_) + ": " + message_), errorCode(errorCode_), message(message_)
59 {
60 }
61 public int errorCode;
62 public string message;
63 }
64 }
65