Overview
An exception related to operating system functions.
This exception is generic in regards to operating system functions, and there are several more specific exceptions for specific functions. However, it is not feasible to create highly-specific exceptions for all OS functions, and much of those cannot be handled gracefully by developers. Some may be so so vague or so specific that it may not be immediately recognized which OS related exception the OS error fits within.
Resolution
Encountering this specific exception typically means that the OS error is not something developers can fix, and will likely require research on the part of the application user or their IT administration teams.
For developers
Implementation
The implementation of this exception is very straight-forward. For example purposes, we will use TypeScript.
The exception must have an exception message, which should provide a description of the reason the exception is being created.
// .. OS attempted to handle something, but failed
const error = lastOSErrorMessage;
const exc = new OSException(`An operating system operation failed. ${lastOSErrorMessage}`);
throw exc;
The exception also accepts an optional exception data parameter, which accepts any key/value pair.
A special key is the cause
key identifying a previous exception. This is useful when you are unable to gracefully (silently) handle errors or exceptions from third-party code (OS code would be considered third-party), and need to identify the actual cause of the exception, while presenting a more specific cause.
try {
someOSErrorThrows();
} catch (e) { // error string from OS
// ... Attempt to handle gracefully
const exc = new OSException('An operating system operation failed.', { cause: new Error(e) });
throw exc;
}
Meta
- Exception code: 0x1 (1)
- Inherits: Exception