Class VisionException


public class VisionException extends RuntimeException

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 Details

  • Constructor Details

    • VisionException

      public VisionException(int code, String message)
      Creates a classified vision failure.
      Parameters:
      code - portable failure code defined by this class
      message - 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 - portable failure code defined by this class
      message - user-readable failure description
      cause - originating detector or image-conversion error
  • Method Details

    • getCode

      public int getCode()
      Returns:
      one of this class's portable failure-code constants