---
title: setCurrentCatalog
description: "Catalog.setCurrentCatalog method in PySpark: Sets the current default catalog in this session."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/catalog/setCurrentCatalog
---

# setCurrentCatalog

Sets the current default catalog in this session.

## Syntax

```
setCurrentCatalog(catalogName: str)
```

## Parameters

| Parameter     | Type | Description                 |
| ------------- | ---- | --------------------------- |
| `catalogName` | str  | Name of the catalog to set. |

## Examples

```python
spark.catalog.setCurrentCatalog("spark_catalog")
```

Setting a catalog that doesn't exist raises an `AnalysisException` with the `NO_SUCH_CATALOG_EXCEPTION` error condition, and the current catalog doesn't change. To handle a catalog that might not exist, catch the exception:

```python
from pyspark.errors import AnalysisException

catalog_name = "my_catalog"

try:
    spark.catalog.setCurrentCatalog(catalog_name)
except AnalysisException as e:
    if e.getCondition() == "NO_SUCH_CATALOG_EXCEPTION":
        print(f"Catalog '{catalog_name}' doesn't exist. The current catalog is still '{spark.catalog.currentCatalog()}'.")
    else:
        raise
```
