public static SQLException toSqlState(String message, String debugMessage, Exception cause) {
        log.debug("Exception Message: {}, Debug message: {}", message, debugMessage, cause);

        if (cause == null) {
            return new SQLException(message == null ? "Unknown client error" : message, SQL_STATE_CLIENT_ERROR);
        }

        String exceptionMessage = message == null ? cause.getMessage() : message;

        if (cause instanceof SQLException) {
            return (SQLException) cause;
        } else if (cause instanceof ClientMisconfigurationException) {
            return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause);
        } else if (cause instanceof ConnectionInitiationException) {
            return new SQLException(exceptionMessage, SQL_STATE_CONNECTION_EXCEPTION, cause);
        } else if (cause instanceof ServerException) {
            return new SQLException(exceptionMessage, SQL_STATE_DATA_EXCEPTION, cause);
        } else if (cause instanceof ClientException) {
            return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause);
        } else if (cause instanceof MalformedURLException) {
            return new SQLDataException(exceptionMessage, SQL_STATE_DATA_EXCEPTION, cause);
        }

        return new SQLException(exceptionMessage, SQL_STATE_CLIENT_ERROR, cause);//Default
    }
Convert a {@link Exception} to a {@link SQLException}.
@param message Custom message to use
@param cause {@link Exception} to convert
@return Converted {@link SQLException}
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ExceptionUtils.java