001/* 002 * Copyright (c) 2026, Oracle and/or its affiliates. 003 * 004 * Licensed under the Universal Permissive License Version 1.0 as shown at 005 * https://oss.oracle.com/licenses/upl/ 006 */ 007package com.oracle.database.selectai.model; 008 009/** 010 * Checked exception used by the SDK for database, JDBC, and Select AI 011 * operation failures. 012 * <p> 013 * When the failure originates from {@link java.sql.SQLException}, the SDK 014 * preserves the original exception as the cause and copies the JDBC error code 015 * and SQLState when available. 016 */ 017public class SelectAIException extends Exception { 018 019 /** Serialization version for the checked exception type. */ 020 private static final long serialVersionUID = 1L; 021 022 /** JDBC error code copied from {@link java.sql.SQLException}. */ 023 private final Integer errorCode; 024 /** SQLState copied from {@link java.sql.SQLException}. */ 025 private final String sqlState; 026 027 /** 028 * Creates an exception with only a message. 029 * 030 * @param message error message 031 */ 032 public SelectAIException(String message) { 033 this(message, null, null, null); 034 } 035 036 /** 037 * Creates an exception with a message and root cause. 038 * 039 * @param message error message 040 * @param cause root cause 041 */ 042 public SelectAIException(String message, Throwable cause) { 043 this(message, cause, null, null); 044 } 045 046 /** 047 * Creates an exception with database error metadata. 048 * 049 * @param message error message 050 * @param cause root cause 051 * @param errorCode JDBC error code 052 * @param sqlState SQLState value 053 */ 054 public SelectAIException(String message, Throwable cause, Integer errorCode, String sqlState) { 055 super(message, cause); 056 this.errorCode = errorCode; 057 this.sqlState = sqlState; 058 } 059 060 /** 061 * Returns the JDBC error code when the failure came from JDBC. 062 * 063 * @return JDBC error code, or {@code null} when unavailable 064 */ 065 public Integer getErrorCode() { 066 return errorCode; 067 } 068 069 /** 070 * Returns the SQLState when the failure came from JDBC. 071 * 072 * @return SQLState string, or {@code null} when unavailable 073 */ 074 public String getSqlState() { 075 return sqlState; 076 } 077}