Class VisionException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.codename1.ai.vision.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionVisionException(int code, String message) Creates a classified vision failure.VisionException(int code, String message, Throwable cause) Creates a classified vision failure with its native or port cause. -
Method Summary
Methods inherited from class Throwable
addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
UNSUPPORTED
public static final int UNSUPPORTED- See Also:
-
INVALID_IMAGE
public static final int INVALID_IMAGE- See Also:
-
MODEL_UNAVAILABLE
public static final int MODEL_UNAVAILABLE- See Also:
-
CANCELLED
public static final int CANCELLED- See Also:
-
BACKEND_ERROR
public static final int BACKEND_ERROR- See Also:
-
-
Constructor Details
-
VisionException
Creates a classified vision failure.- Parameters:
code- portable failure code defined by this classmessage- user-readable failure description
-
VisionException
-
-
Method Details
-
getCode
public int getCode()- Returns:
- one of this class's portable failure-code constants
-