Errors versus exceptions
Runtime faults can and do occur during the execution of a Dart program. We can split all faults into two types:
- Errors
- Exceptions
There is always some confusion on deciding when to use each kind of fault, but you will be given several general rules to make your life a bit easier. All your decisions will be based on the simple principle of recoverability. If your code generates a fault that can reasonably be recovered from, use exceptions. Conversely, if the code generates a fault that cannot be recovered from, or where continuing the execution would do more harm, use errors.
Let's take a look at each of them in detail.
Errors
An error occurs if your code has programming errors that should be fixed by the programmer. Let's take a look at the following main
function:
main() { // Fixed length list List list = new List(5); // Fill list with values for (int i = 0; i < 10; i++) { list[i] = i; } print('Result is ${list}'); }
We created an...