RuntimeError
What is RuntimeError?
RuntimeError: A general catch-all error category raised when something goes wrong during execution that doesn't fit a more specific type. RuntimeError is a general error type for problems that happen while a program runs and do not fit a more specific category. Python raises it for various unexpected situations, and PHP has RuntimeException as a base for errors that can only be detected at runtime.
Frequently asked questions about RuntimeError
How is RuntimeError used in practice?
Because it is so general, the message carries most of the information. Read it carefully, and look at the stack trace to see where it came from.
What should you keep in mind with RuntimeError?
When you throw errors in your own code, prefer specific exception classes, such as PaymentDeclinedException or InvoiceAlreadySentException. Callers can then catch exactly the problems they know how to handle, and your logs say clearly what went wrong. Catching every RuntimeException broadly tends to hide bugs that should have been fixed.
At a glance
| Category | Error types |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |