diff options
author | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-02-22 09:31:21 +0200 |
---|---|---|
committer | Ander Conselvan de Oliveira <ander.deoliveira@mapbox.com> | 2019-03-13 11:58:27 +0200 |
commit | 7d1911572000d1353c1c0109402431323fcd8639 (patch) | |
tree | 4881a1e159415cd796e255bec951a7bb32b23ee8 /platform/macos | |
parent | 565792606d5d03d0cc9889f112bb50345c899005 (diff) | |
download | qtlocation-mapboxgl-7d1911572000d1353c1c0109402431323fcd8639.tar.gz |
[core] Don't use exceptions in MapObserver::onDidFailLoadingMap
Using different exception pointers to specify the loading failure makes
an awkward API. Most users rethrow the exception only to figure out what
type of error happened so it can be reported properly. So replace the
exception pointer with a enum an string description of the failure.
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index fa207ec187..7edf34574d 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -3062,27 +3062,29 @@ public: [nativeView mapViewDidFinishLoadingMap]; } - void onDidFailLoadingMap(std::exception_ptr exception) override { + void onDidFailLoadingMap(mbgl::MapLoadError mapError, const std::string& what) override { NSString *description; MGLErrorCode code; - try { - std::rethrow_exception(exception); - } catch (const mbgl::util::StyleParseException&) { - code = MGLErrorCodeParseStyleFailed; - description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @"User-friendly error description"); - } catch (const mbgl::util::StyleLoadException&) { - code = MGLErrorCodeLoadStyleFailed; - description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @"User-friendly error description"); - } catch (const mbgl::util::NotFoundException&) { - code = MGLErrorCodeNotFound; - description = NSLocalizedStringWithDefaultValue(@"STYLE_NOT_FOUND_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @"User-friendly error description"); - } catch (...) { - code = MGLErrorCodeUnknown; - description = NSLocalizedStringWithDefaultValue(@"LOAD_MAP_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @"User-friendly error description"); + switch (mapError) { + case mbgl::MapLoadError::StyleParseError: + code = MGLErrorCodeParseStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"PARSE_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style is corrupted.", @"User-friendly error description"); + break; + case mbgl::MapLoadError::StyleLoadError: + code = MGLErrorCodeLoadStyleFailed; + description = NSLocalizedStringWithDefaultValue(@"LOAD_STYLE_FAILED_DESC", nil, nil, @"The map failed to load because the style can't be loaded.", @"User-friendly error description"); + break; + case mbgl::MapLoadError::NotFoundError: + code = MGLErrorCodeNotFound; + description = NSLocalizedStringWithDefaultValue(@"STYLE_NOT_FOUND_DESC", nil, nil, @"The map failed to load because the style can’t be found or is incompatible.", @"User-friendly error description"); + break; + default: + code = MGLErrorCodeUnknown; + description = NSLocalizedStringWithDefaultValue(@"LOAD_MAP_FAILED_DESC", nil, nil, @"The map failed to load because an unknown error occurred.", @"User-friendly error description"); } NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: description, - NSLocalizedFailureReasonErrorKey: @(mbgl::util::toString(exception).c_str()), + NSLocalizedFailureReasonErrorKey: @(what.c_str()), }; NSError *error = [NSError errorWithDomain:MGLErrorDomain code:code userInfo:userInfo]; [nativeView mapViewDidFailLoadingMapWithError:error]; |