| Start |
|---|
| Creating a custom exception type A custom exception is any class that extends In general, you should always extend It's common to name exceptions by adding the
However, when the error is self-explanatory, you don't need to add the
|
| Handling multiple exceptions You can handle multiple errors in the same You can also add multiple The order of the Some blocks have implicit exception handling like |
| Handling an exception Use the A A bare Note: Take care to avoid catching You can also specify the exception class that should be rescued: This rescue clause will not catch any exception that is not a You can also store the exception in a specific variable: If you failed to handle an exception, you can raise it any time in a rescue block. If you want to retry your You can be stuck in a loop if you catch an exception in every retry. To avoid this, limit your You can also provide an If you are inside a |
| Raising an exception To raise an exception use You can also simply pass an error message. In this case, the message is wrapped into a Here's an example: |
| Adding information to (custom) exceptions It may be helpful to include additional information with an exception, e.g. for logging purposes or to allow conditional handling when the exception is caught: Raising the exception: Catching the exception and accessing the additional information provided: RemarksAn exception is an object that represents the occurrence of an exceptional condition. In other words, it indicates that something went wrong. In Ruby, exceptions are often referred to as errors. That's because the base |
Read Article
https://develop.horje.com/learn/1434/reference