[android] catch and re-throw throwables thrown inside map state callbacks

This commit is contained in:
Łukasz Paczos
2018-11-13 12:47:40 +01:00
committed by Łukasz Paczos
parent 6afc63caf7
commit 0df37421fa
3 changed files with 287 additions and 95 deletions

View File

@@ -29,36 +29,18 @@ public class MapStrictMode {
/**
* Internal use. Called whenever the strict mode violation occurs.
*/
public static void strictModeViolation(String message, Exception exception) {
public static void strictModeViolation(String message, Throwable throwable) {
if (strictModeEnabled) {
throw new MapStrictModeException(String.format("%s - %s", message, exception));
throw new MapStrictModeException(String.format("%s - %s", message, throwable));
}
}
/**
* Internal use. Called whenever the strict mode violation occurs.
*/
public static void strictModeViolation(String message, Error error) {
public static void strictModeViolation(Throwable throwable) {
if (strictModeEnabled) {
throw new MapStrictModeException(String.format("%s - %s", message, error));
}
}
/**
* Internal use. Called whenever the strict mode violation occurs.
*/
public static void strictModeViolation(Error error) {
if (strictModeEnabled) {
throw new MapStrictModeException(String.format("%s", error));
}
}
/**
* Internal use. Called whenever the strict mode violation occurs.
*/
public static void strictModeViolation(Exception exception) {
if (strictModeEnabled) {
throw new MapStrictModeException(String.format("%s", exception));
throw new MapStrictModeException(String.format("%s", throwable));
}
}
}

View File

@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.maps;
import com.mapbox.mapboxsdk.MapStrictMode;
import com.mapbox.mapboxsdk.log.Logger;
import java.util.List;
@@ -39,9 +38,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onCameraWillChangeListener.onCameraWillChange(animated);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onCameraWillChange", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -53,9 +52,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onCameraIsChangingListener.onCameraIsChanging();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onCameraIsChanging", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -67,9 +66,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onCameraDidChangeListener.onCameraDidChange(animated);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onCameraDidChange", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -81,9 +80,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onWillStartLoadingMapListener.onWillStartLoadingMap();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onWillStartLoadingMap", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -95,9 +94,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onDidFinishLoadingMapListener.onDidFinishLoadingMap();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFinishLoadingMap", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -109,9 +108,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onDidFailLoadingMapListener.onDidFailLoadingMap(error);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFailLoadingMap", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -123,9 +122,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
listener.onWillStartRenderingFrame();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onWillStartRenderingFrame", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -137,9 +136,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
listener.onDidFinishRenderingFrame(fully);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFinishRenderingFrame", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -151,9 +150,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
listener.onWillStartRenderingMap();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onWillStartRenderingMap", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -165,9 +164,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
listener.onDidFinishRenderingMap(fully);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFinishRenderingMap", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -179,9 +178,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
listener.onDidFinishLoadingStyle();
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onDidFinishLoadingStyle", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}
@@ -193,9 +192,9 @@ class MapChangeReceiver implements NativeMapView.StateCallback {
onSourceChangedListener.onSourceChangedListener(sourceId);
}
}
} catch (RuntimeException err) {
} catch (Throwable err) {
Logger.e(TAG, "Exception in onSourceChanged", err);
MapStrictMode.strictModeViolation(err);
throw err;
}
}