check for newer exceptions inside of the error listener handling

pull/59/merge^2
Tim H 7 years ago
parent 910f4da42c
commit 1f748c36ae
  1. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 13
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -797,8 +797,8 @@ class Camera1 extends CameraController {
return true;
}
catch (Exception e) {
// at least setParameters may fail.
// TODO why does it fail and is it possible to prevent such errors?
// at least getParameters and setParameters may fail.
// TODO why do they fail and is it possible to prevent such errors?
CameraException cameraException = new CameraConfigurationFailedException("Failed to " +
"start auto focus.", e);
mCameraCallbacks.onError(cameraException);

@ -1579,15 +1579,24 @@ public class CameraView extends FrameLayout {
public void run() {
// all error listeners will be called, but at most one of them should actually
// throw the exception
// throw an exception
int count = 0;
for (CameraListener listener : mListeners) {
try {
listener.onError(exception);
} catch (CameraException ce) {
count++;
// if a custom error handler caused a new exception, we throw the new
// one instead of the original one
if (ce == exception) {
count++;
}
else {
throw ce;
}
}
}
// the original exception is only thrown, if all existing listeners threw it
if (count == mListeners.size()) {
throw exception;
}

Loading…
Cancel
Save