Implementation:Microsoft Onnxruntime OrtException: Difference between revisions
Appearance
Auto-imported from implementations/Microsoft_Onnxruntime_OrtException.md |
Sync from local file |
||
| Line 98: | Line 98: | ||
== Related Pages == | == Related Pages == | ||
* [[Microsoft_Onnxruntime_OrtSession|OrtSession.java]] - Throws OrtException from session methods | * [[Implementation:Microsoft_Onnxruntime_OrtSession|OrtSession.java]] - Throws OrtException from session methods | ||
* [[Microsoft_Onnxruntime_OrtEnvironment|OrtEnvironment.java]] - Throws OrtException from environment creation | * [[Implementation:Microsoft_Onnxruntime_OrtEnvironment|OrtEnvironment.java]] - Throws OrtException from environment creation | ||
* [[Microsoft_Onnxruntime_OrtTrainingSession|OrtTrainingSession.java]] - Throws OrtException from training methods | * [[Implementation:Microsoft_Onnxruntime_OrtTrainingSession|OrtTrainingSession.java]] - Throws OrtException from training methods | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:46, 27 September 2026
| Knowledge Sources | Description |
|---|---|
| Source File | java/src/main/java/ai/onnxruntime/OrtException.java |
| Repository | Microsoft/onnxruntime |
Domains
- Machine Learning Runtime
- Error Handling
Overview
OrtException is a checked exception containing the error message and error code produced by the native ONNX Runtime or by Java-side validation. It extends Exception and includes the inner enum OrtErrorCode which maps all native error codes (ORT_OK through ORT_NOT_FOUND) plus a Java-specific ORT_JAVA_UNKNOWN sentinel value.
Description
The class provides:
- Constructors: Three variants accepting (String), (int, String), or (OrtErrorCode, String). The int-based constructor is used by native JNI code.
- Error code access:
getCode()returns theOrtErrorCode.
The OrtErrorCode enum maps the native OrtErrorCode struct from onnxruntime_c_api.h:
- ORT_JAVA_UNKNOWN (-1), ORT_OK (0), ORT_FAIL (1), ORT_INVALID_ARGUMENT (2), ORT_NO_SUCHFILE (3), ORT_NO_MODEL (4), ORT_ENGINE_ERROR (5), ORT_RUNTIME_EXCEPTION (6), ORT_INVALID_PROTOBUF (7), ORT_MODEL_LOADED (8), ORT_NOT_IMPLEMENTED (9), ORT_INVALID_GRAPH (10), ORT_EP_FAIL (11), ORT_MODEL_LOAD_CANCELED (12), ORT_MODEL_REQUIRES_COMPILATION (13), ORT_NOT_FOUND (14).
Code Reference
Source Location
// File: java/src/main/java/ai/onnxruntime/OrtException.java
// Package: ai.onnxruntime
Signature
public class OrtException extends Exception {
public OrtException(String message);
public OrtException(int code, String message);
public OrtException(OrtErrorCode code, String message);
public OrtErrorCode getCode();
public enum OrtErrorCode {
ORT_JAVA_UNKNOWN(-1), ORT_OK(0), ORT_FAIL(1),
ORT_INVALID_ARGUMENT(2), ORT_NO_SUCHFILE(3), ORT_NO_MODEL(4),
ORT_ENGINE_ERROR(5), ORT_RUNTIME_EXCEPTION(6), ORT_INVALID_PROTOBUF(7),
ORT_MODEL_LOADED(8), ORT_NOT_IMPLEMENTED(9), ORT_INVALID_GRAPH(10),
ORT_EP_FAIL(11), ORT_MODEL_LOAD_CANCELED(12),
ORT_MODEL_REQUIRES_COMPILATION(13), ORT_NOT_FOUND(14);
public static OrtErrorCode mapFromInt(int value);
}
}
Import
import ai.onnxruntime.OrtException;
import ai.onnxruntime.OrtException.OrtErrorCode;
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
| code | int or OrtErrorCode | The native error code |
| message | String | The error description |
Outputs
| Name | Type | Description |
|---|---|---|
| getCode() | OrtErrorCode | The structured error code |
| getMessage() | String | The formatted error message (inherited from Exception) |
Usage Examples
import ai.onnxruntime.*;
OrtEnvironment env = OrtEnvironment.getEnvironment();
try {
OrtSession session = env.createSession("/nonexistent/model.onnx");
} catch (OrtException e) {
System.err.println("Error code: " + e.getCode()); // e.g., ORT_NO_SUCHFILE
System.err.println("Message: " + e.getMessage());
if (e.getCode() == OrtException.OrtErrorCode.ORT_NO_SUCHFILE) {
System.err.println("Model file not found.");
}
}
Related Pages
- OrtSession.java - Throws OrtException from session methods
- OrtEnvironment.java - Throws OrtException from environment creation
- OrtTrainingSession.java - Throws OrtException from training methods