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

# How to Handle PSD Core Exceptions in .NET

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

Aspose.PSD FOSS for .NET defines two exception types: `PsdLoadException`,
thrown while parsing a PSD/PSB document, and `PsdSaveException`, thrown while
writing one. Both derive from `System.Exception` and support a
message-only constructor and a message-plus-inner-exception constructor.

## Step-by-Step Guide

### Step 1: Install the Package

```bash
dotnet add package Aspose.PSD.FOSS
```

---

### Step 2: Import Required Classes

```csharp
using Aspose.PSD.FileFormats.Psd;
```

---

### Step 3: Catch Load-Time Failures

`PsdLoadException` is thrown 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:

```csharp
try
{
    using var image = PsdImage.Load("input.psd");
}
catch (PsdLoadException ex)
{
    Console.WriteLine($"Failed to load PSD/PSB file: {ex.Message}");
}
```

---

### Step 4: Catch Save-Time Failures

`PsdSaveException` is thrown while writing a document — for example, when a
string value exceeds the length a PSD Pascal string field can hold:

```csharp
try
{
    image.Save("output.psd");
}
catch (PsdSaveException ex)
{
    Console.WriteLine($"Failed to save PSD/PSB file: {ex.Message}");
}
```

---

### Step 5: Inspect an Inner Exception

Both exception types have a constructor that wraps an inner exception (used
internally, for example, when an I/O error interrupts reading the file
structure). Check `InnerException` for the underlying cause:

```csharp
try
{
    using var image = PsdImage.Load("input.psd");
}
catch (PsdLoadException ex) when (ex.InnerException != null)
{
    Console.WriteLine($"Underlying I/O error: {ex.InnerException.Message}");
}
```

## 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 `System.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 throw 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 .NET exception type rather
than being wrapped in `PsdSaveException`.

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

Yes, since both derive from `System.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-dotnet/)
- [Working with Layers](../how-to-work-with-layers-dotnet/)
- [Aspose.PSD FOSS for .NET — Frequently Asked Questions](../faq/)
- [Aspose.PSD for .NET — Enterprise Knowledge Base](https://kb.aspose.com/psd/net/)