diff --git a/README.md b/README.md index 18373dc2..650768cf 100644 --- a/README.md +++ b/README.md @@ -220,8 +220,9 @@ camera.addCameraListener(new CameraListener() { /** * Notifies that an error occurred in any of the previously called methods. * The default implementation will just throw the original exception again to prevent missing - * error handling. Override this method without calling the super method in order to implement - * custom error handling. + * error handling. As soon as this method was overridden at least once (without calling the + * super method or re-throwing the exception), the default behavior will be disabled. So pay + * attention to not swallowing any exceptions. */ @Override public void onError(CameraException exception) { diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraException.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraException.java index 8e28309b..ec587c78 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraException.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraException.java @@ -5,7 +5,7 @@ package com.otaliastudios.cameraview; */ public class CameraException extends RuntimeException { - public CameraException(String message, Throwable cause) { + CameraException(String message, Throwable cause) { super(message, cause); } -} +} \ No newline at end of file diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index d2f441f5..024de527 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1571,8 +1571,19 @@ public class CameraView extends FrameLayout { mUiHandler.post(new Runnable() { @Override public void run() { + + // all error listeners will be called, but at most one of them should actually + // throw the exception + int count = 0; for (CameraListener listener : mListeners) { - listener.onError(exception); + try { + listener.onError(exception); + } catch (CameraException ce) { + count++; + } + } + if (count == mListeners.size()) { + throw exception; } } });