geospatial
geospatial copied to clipboard
Ensure FormatException, not errors, is thrown when parsing invalid input data from external data sources
Background
- Error vs. Exception in Dart
- Error vs Exception? Why both? When to use which? When to subclass which?
Bob Nyström (2013):
- Error and its subclasses are for programmatic errors. If one of those occurs, your code is bad and you should fix your code.
- Non-Error exception classes are for runtime errors. Sometimes you can prevent them from being thrown, but often you cannot.
- Except in a few special circumstances, idiomatic Dart should throw Errors, but never catch them. They exists specifically to not be caught so that they take down the app and alert the programmer to the location of the bug.
When parsing data from some external data source, like WKT or GeoJSON data, in the scope of this library, such external data might have invalid data that parser code must handle. When encountering invalid data, and if a parser cannot handle such invalid data, it might be better to throw an exception (like FormatException in Dart) rather than throwing an error. Invalid data from an external data source or file are not programmatic errors.
Some code in geocore still might throw errors when reading (and cannot handle) invalid data. So must check and correct such occurences if found.