[core] Rationalize error handling for resource loading

* Standardize on std::exception_ptr as the error representation
  (fixes #2854).
* Don't format textual strings at the error source; pass on the
  constituent data via observer method parameters instead.
* Use the null object pattern to simplify observer notification code.
* Further refactoring for ResourceLoading tests.
This commit is contained in:
John Firebaugh
2015-12-22 15:10:24 -08:00
parent 7bd4745cf1
commit 16de579d7c
28 changed files with 405 additions and 472 deletions

View File

@@ -18,18 +18,12 @@ public:
void parseRasterTile(std::unique_ptr<RasterBucket> bucket,
const std::shared_ptr<const std::string> data,
std::function<void(RasterTileParseResult)> callback) {
PremultipliedImage image;
try {
image = decodeImage(*data);
bucket->setImage(decodeImage(*data));
callback(RasterTileParseResult(std::move(bucket)));
} catch (...) {
callback(RasterTileParseResult("error parsing raster image"));
return;
callback(std::current_exception());
}
bucket->setImage(std::move(image));
callback(RasterTileParseResult(std::move(bucket)));
}
void parseGeometryTile(TileWorker* worker,
@@ -39,8 +33,8 @@ public:
std::function<void(TileParseResult)> callback) {
try {
callback(worker->parseAllLayers(std::move(layers), *tile, config));
} catch (const std::exception& ex) {
callback(TileParseResult(ex.what()));
} catch (...) {
callback(std::current_exception());
}
}
@@ -48,8 +42,8 @@ public:
std::function<void(TileParseResult)> callback) {
try {
callback(worker->parsePendingLayers());
} catch (const std::exception& ex) {
callback(TileParseResult(ex.what()));
} catch (...) {
callback(std::current_exception());
}
}