private static SQLException create(Throwable e) {
        if (e == null) {
            return unknownError();
        } else if (e instanceof ClickHouseException) {
            return handle((ClickHouseException) e);
        } else if (e instanceof SQLException) {
            return (SQLException) e;
        }

        Throwable cause = e.getCause();
        if (cause instanceof ClickHouseException) {
            return handle((ClickHouseException) cause);
        } else if (cause instanceof SQLException) {
            return (SQLException) cause;
        } else if (cause == null) {
            cause = e;
        }

        return new SQLException(cause);
    }
Helper class for building {@link SQLException}.
clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/SqlExceptionUtils.java