public class VisionException
- Object
- Throwable
- Exception
- RuntimeException
- VisionException
Failure reported by an on-device vision backend.
The code separates “this device will never do this” from “this attempt failed”, which usually calls for different UI:
recognizer.process(image)
.ready(result -> textArea.setText(result.getText()))
.except(error -> {
if (error instanceof VisionException
&& ((VisionException) error).getCode()
== VisionException.UNSUPPORTED) {
// Permanent: hide the feature rather than offering a retry.
scanButton.setVisible(false);
return;
}
ToastBar.showErrorMessage("Could not read that image");
Log.e(error);
});
Prefer isSupported() on the analyzer to reaching this state at all;
UNSUPPORTED is the answer to a question that could have been asked
before the screen was shown.
Fields
Constructors
public VisionException(int code, String message) | Creates a classified vision failure. |
public VisionException(int code, String message, Throwable cause) | Creates a classified vision failure with its native or port cause. |
Methods
public int getCode() |
Inherited methods
Field details
UNSUPPORTED
public static final int UNSUPPORTED = 1INVALID_IMAGE
public static final int INVALID_IMAGE = 2MODEL_UNAVAILABLE
public static final int MODEL_UNAVAILABLE = 3CANCELLED
public static final int CANCELLED = 4BACKEND_ERROR
public static final int BACKEND_ERROR = 5Constructor details
VisionException
public VisionException(int code, String message)Creates a classified vision failure.
Parameters
codeint- portable failure code defined by this class
messageString- user-readable failure description
VisionException
public VisionException(int code, String message, Throwable cause)Creates a classified vision failure with its native or port cause.
Parameters
codeint- portable failure code defined by this class
messageString- user-readable failure description
causeThrowable- originating detector or image-conversion error
Method details
getCode
public int getCode()Returns
one of this class’s portable failure-code constants