Exceptions - mgismissing/cosmos GitHub Wiki
Exceptions are a reimplementation of the exception system found in almost every programming language.
When an exception is raised, the system logs some details about it and halts code execution with control.panic
with an exception-specific code.
Custom exceptions can be created by either customizing a new Exception
object or by extending any already existing Exception
class and overriding its constructor.
Example of a customized Exception
object:
new Exception("CustomException", "A custom exception occurred: foo bar!", 404)
Example of an Exception
extension:
class CustomException extends Exception {
constructor(comment: String) {
super("CustomException", "A custom exception occurred: " + comment + "!", 404)
}
}
new CustomException("foo bar").raise()
The general function raise
is also present:
raise(new Exception("CustomException", "A custom exception occurred: foo bar!", 404))
Here is a list of all the exceptions that Cosmos adds with their panic code and the appropriate meaning:
Name | Panic code | Meaning |
---|---|---|
NotImplementedException |
100 |
This part is being worked on and should not be used at the moment. |
OutOfRangeException |
101 |
The given value is not between another minimum and maximum value. |
AlreadyInUseException |
102 |
The requested resource is already being used elsewhere. |