public class VisionException

  1. Object
  2. Throwable
  3. Exception
  4. RuntimeException
  5. 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

public static final int UNSUPPORTED = 1
public static final int INVALID_IMAGE = 2
public static final int MODEL_UNAVAILABLE = 3
public static final int CANCELLED = 4
public static final int BACKEND_ERROR = 5

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 = 1

INVALID_IMAGE

public static final int INVALID_IMAGE = 2

MODEL_UNAVAILABLE

public static final int MODEL_UNAVAILABLE = 3

CANCELLED

public static final int CANCELLED = 4

BACKEND_ERROR

public static final int BACKEND_ERROR = 5

Constructor details

VisionException

public VisionException(int code, String message)
Creates a classified vision failure.

Parameters

code int
portable failure code defined by this class
message String
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

code int
portable failure code defined by this class
message String
user-readable failure description
cause Throwable
originating detector or image-conversion error

Method details

getCode

public int getCode()

Returns

one of this class’s portable failure-code constants