CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBException.cpp
Go to the documentation of this file.
1 #include "CYB.hpp"
3 
4 namespace CYB {
5  namespace Exception {
7  thread_local unsigned int FLastInstantiatedExceptionCode;
8  };
9 };
10 
12  API::Assert::LessThanOrEqual(AErrorCode, UNSUPPORTED_ALLOCATION_AMOUNT);
13  API::String::Static ErrorMessage;
14  switch (AErrorCode) {
15  case INVALID_ENUM:
16  ErrorMessage = API::String::Static(u8"An operation was attempted with an invalid enum code");
17  break;
18  case INVALID_INTEROP_CONSTRUCTOR:
19  ErrorMessage = API::String::Static(u8"An engine allocation was attempted with a malformed constructor");
20  break;
21  case INVALID_OPERATION:
22  ErrorMessage = API::String::Static(u8"An illegal call was made given prexisting conditions");
23  break;
24  case INVALID_PARAMETERS:
25  ErrorMessage = API::String::Static(u8"The current arrangment of arguments passed the function is invalid");
26  break;
27  case NEGATIVE_HEAP_ALLOCATION:
28  ErrorMessage = API::String::Static(u8"Alloc or Realloc called with a negative size value");
29  break;
30  case UNSUPPORTED_ALLOCATION_AMOUNT:
31  ErrorMessage = API::String::Static(u8"An allocation was attempted with a size greater than 2047MB");
32  break;
33  }
34  return ErrorMessage;
35 }
36 CYB::Exception::Violation::Violation(const ErrorCode AErrorCode) noexcept :
37  Base(ErrorMessage(AErrorCode), AErrorCode, Level::VIOLATION)
38 {
39  FLastInstantiatedExceptionCode = AErrorCode;
40 }
41 
43  API::Assert::LessThanOrEqual(AErrorCode, THREAD_CREATION_FAILURE);
44  API::String::Static ErrorMessage;
45  switch (AErrorCode) {
46  case DIRECTORY_NOT_EMPTY:
47  ErrorMessage = API::String::Static(u8"Tried to delete a non-empty directory");
48  break;
49  case FILE_EXISTS:
50  ErrorMessage = API::String::Static(u8"Tried to exclusively create a file that exists");
51  break;
52  case FILE_NOT_FOUND:
53  ErrorMessage = API::String::Static(u8"A required file was not found.");
54  break;
55  case STREAM_NOT_READABLE:
56  ErrorMessage = API::String::Static(u8"Generic error for read failures. See functions for further documentation");
57  break;
58  case STREAM_NOT_WRITABLE:
59  ErrorMessage = API::String::Static(u8"Generic error for write failures. See functions for further documentation");
60  break;
61  case HEAP_ALLOCATION_FAILURE:
62  ErrorMessage = API::String::Static(u8"Current heap has no block large enough for a requested allocation and expansion failed");
63  break;
64  case MUTEX_INITIALIZATION_FAILURE:
65  ErrorMessage = API::String::Static(u8"Failed to initialize a new mutex.");
66  break;
67  case PATH_LOST:
68  ErrorMessage = API::String::Static(u8"Path has become invalidated, most likely due to deletion");
69  break;
70  case PATH_TOO_LONG:
71  ErrorMessage = API::String::Static(u8"Attempted to use a path greater than the maximum allowed byte value");
72  break;
73  case STRING_VALIDATION_FAILURE:
74  ErrorMessage = API::String::Static(u8"A string could not be validated");
75  break;
76  case SYSTEM_PATH_RETRIEVAL_FAILURE:
77  ErrorMessage = API::String::Static(u8"A system path could not be retrieved");
78  break;
79  case THREAD_CREATION_FAILURE:
80  ErrorMessage = API::String::Static(u8"OS failed to create requested thread.");
81  break;
82  }
83  return ErrorMessage;
84 }
85 
87  Base(ErrorMessage(AErrorCode), AErrorCode, Level::SYSTEM_DATA)
88 {
89  FLastInstantiatedExceptionCode = AErrorCode;
90 }
92  API::Assert::LessThanOrEqual(AErrorCode, PROCESS_TERMINATION_ERROR);
93  API::String::Static ErrorMessage;
94  switch (AErrorCode) {
95  case MEMORY_COMMITAL_FAILURE:
96  ErrorMessage = API::String::Static(u8"Failed to commit virtual memory from the OS.");
97  break;
98  case MEMORY_PROTECT_FAILURE:
99  ErrorMessage = API::String::Static(u8"Failed to implement requested virtual memory protection level.");
100  break;
101  case MEMORY_RESERVATION_FAILURE:
102  ErrorMessage = API::String::Static(u8"Failed to reserve virtual memory from the OS.");
103  break;
104  case MODULE_FUNCTION_LOAD_FAILURE:
105  ErrorMessage = API::String::Static(u8"Failed to load a requested function from a module.");
106  break;
107  case MODULE_LOAD_FAILURE:
108  ErrorMessage = API::String::Static(u8"Failed to load a requested module.");
109  break;
110  case PATH_EVALUATION_FAILURE:
111  ErrorMessage = API::String::Static(u8"Failed to evaluate a Path.");
112  break;
113  case PROCESS_CREATION_ERROR:
114  ErrorMessage = API::String::Static(u8"Failed to create Process for unknown reasons.");
115  break;
116  case PROCESS_EXIT_CODE_UNCHECKABLE:
117  ErrorMessage = API::String::Static(u8"Tried to check the error code of a Process the OS would not allow.");
118  break;
119  case PROCESS_TERMINATION_ERROR:
120  ErrorMessage = API::String::Static(u8"Failed to terminate process, most likely due to insufficient permissions.");
121  break;
122  };
123  return ErrorMessage;
124 }
125 
126 CYB::Exception::Internal::Internal(const ErrorCode AErrorCode) noexcept :
127  Base(ErrorMessage(AErrorCode), AErrorCode, Level::INTERNAL)
128 {
129  FLastInstantiatedExceptionCode = AErrorCode;
130 }
ErrorCode
The error code of the exception.
Definition: Exception.hpp:107
static API::String::Static ErrorMessage(const ErrorCode AErrorCode) noexcept
Get the associated message for an exception.
ErrorCode
The error code of the exception.
Definition: Exception.hpp:35
thread_local unsigned int FLastInstantiatedExceptionCode
Used to better verify tests, should be optimized out by the linker. See: http://stackoverflow.com/questions/1229430/how-do-i-prevent-my-unused-global-variables-being-compiled-out.
Definition: CYBException.cpp:7
A string pointing to unchanging data in the stack above it or the data segment. Must have UTF-8 encod...
Definition: StaticString.hpp:7
static API::String::Static ErrorMessage(const ErrorCode AErrorCode) noexcept
Get the associated message for an exception.
Internal(const ErrorCode AErrorCode) noexcept
Construct an Internal exception.
SystemData(const ErrorCode AErrorCode) noexcept
Construct a SystemData exception.
static API::String::Static ErrorMessage(const ErrorCode AErrorCode) noexcept
Get the associated message for an exception.
Precompiled header for inter-engine operations.
ErrorCode
The error code of the exception.
Definition: Exception.hpp:68
Violation(const ErrorCode AErrorCode) noexcept
Construct a Violation exception.
The base exception recognized by the entire engine.
Definition: Exception.hpp:7