geospatial icon indicating copy to clipboard operation
geospatial copied to clipboard

Ensure FormatException, not errors, is thrown when parsing invalid input data from external data sources

Open navispatial opened this issue 2 years ago • 0 comments

Background

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.

navispatial avatar Nov 25 '21 18:11 navispatial