---
Product: psd
Platform: python
Page Type: kb
Canonical URL: https://kb.aspose.org/psd/python/how-to-work-with-psd-core-exceptions-python
Last Updated: 2026-10-08
---

# How to Handle PSD Core Exceptions in Python

Catch and handle PsdLoadException and PsdSaveException — the two Aspose.PSD FOSS for Python exception types raised while parsing or writing PSD/PSB documents.

Aspose.PSD FOSS for Python defines two exception types: `PsdLoadException`,
raised while parsing a PSD/PSB document, and `PsdSaveException`, raised while
writing one. Both derive from the built-in `Exception` and accept a
message plus an optional inner exception.

## Step-by-Step Guide

### Step 1: Install the Package

```bash
pip install aspose-psd-foss
```

---

### Step 2: Import Required Classes

```python
from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.coreexceptions.psdloadexception import PsdLoadException
from aspose_psd_foss.coreexceptions.psdsaveexception import PsdSaveException
```

---

### Step 3: Catch Load-Time Failures

`PsdLoadException` is raised when a document's structure fails validation —
for example, an unsupported PSD/PSB version, a section length that exceeds
the enclosing section's declared boundary, or truncated stream data:

```python
try:
    image = PsdImage.load("input.psd")
except PsdLoadException as ex:
    print(f"Failed to load PSD/PSB file: {ex}")
```

---

### Step 4: Catch Save-Time Failures

`PsdSaveException` is raised while writing a document — for example, when a
string value exceeds the length a PSD Pascal string field can hold (255
bytes):

```python
try:
    image.save("output.psd")
except PsdSaveException as ex:
    print(f"Failed to save PSD/PSB file: {ex}")
```

---

### Step 5: Inspect an Inner Exception

Both exception types accept an `inner_exception` constructor argument (used
internally, for example, when an I/O error interrupts reading the file
structure). Check `inner_exception` for the underlying cause:

```python
try:
    image = PsdImage.load("input.psd")
except PsdLoadException as ex:
    if ex.inner_exception is not None:
        print(f"Underlying I/O error: {ex.inner_exception}")
```

## Common Issues and Fixes

**`PsdLoadException` with a message about an unsupported version.** The
file's declared PSD version field is neither the standard PSD nor the
large-document PSB value. Confirm the file is a genuine, uncorrupted
PSD/PSB document.

**`PsdLoadException` with a message about a section length exceeding a
boundary.** The file's internal length fields are inconsistent with its
actual size — this usually indicates a truncated or corrupted file rather
than an unsupported variant.

**`PsdSaveException` about a Pascal string length.** A string value (such as
a layer or resource name) exceeds 255 bytes, the maximum a PSD Pascal string
field can encode. Shorten the value before saving.

## Frequently Asked Questions

### Do PsdLoadException and PsdSaveException share a common base exception type?

No — both derive directly from the built-in `Exception`, not from each
other or a shared Aspose.PSD base exception class.

### Can PsdSaveException occur for reasons other than a long string value?

The confirmed raise site in this FOSS build is the Pascal-string-length
check. Other save-time I/O failures (for example, a destination stream that
cannot be written to) surface as the underlying Python exception type rather
than being wrapped in `PsdSaveException`.

### Will catching `Exception` also catch these two types?

Yes, since both derive from `Exception` — but catching the specific types
lets you distinguish load failures from save failures.

## See Also

- [Working with the Core API](../how-to-work-with-psd-core-api-python/)
- [Working with Layers](../how-to-work-with-layers-python/)
- [Aspose.PSD FOSS for Python — Frequently Asked Questions](../faq/)
- [Aspose.PSD — Enterprise Knowledge Base](https://kb.aspose.com/psd/)