OSException
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 vague or so specific that it may not be immediately recognized which OS related exception the OS error fits within.
Note
Exception is too generic to infer any useful 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.
Implementation
Important
This exception is meant as a last resort when you are unable to classify operating system errors which cannot be handled gracefully.
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.
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) {
const exc = new OSException(
'An operating system operation failed.',
{ cause: new Error(e) }
);
throw exc;
}