Core Exceptions
Core Exceptions
The library reports load and save failures through two dedicated exception types: PsdLoadException and PsdSaveException, both extending the standard Exception class.
PsdLoadException
Thrown when Image.Load() / PsdImage.Load() cannot parse the input as a valid PSD or PSB document.
try
{
using var image = (PsdImage)Image.Load(inputPath);
}
catch (PsdLoadException ex)
{
Console.WriteLine($"Failed to load {inputPath}: {ex.Message}");
}PsdSaveException
Thrown when PsdImage.Save() cannot write the document out.
try
{
image.Save(outputPath);
}
catch (PsdSaveException ex)
{
Console.WriteLine($"Failed to save {outputPath}: {ex.Message}");
}Constructors
Both exception types have the same two-constructor shape: a message-only constructor, and a message-plus-inner-exception constructor for wrapping a lower-level failure.
throw new PsdLoadException("Unexpected end of stream while reading the PSD header.");
throw new PsdSaveException("Failed to write layer data.", innerException);Tips and Best Practices
- Catch
PsdLoadExceptionaround everyImage.Load()/PsdImage.Load()call that processes external input. - Catch
PsdSaveExceptionaround everyPsdImage.Save()call if the destination (disk, stream) might not be writable. - Both types extend
Exception, so a broadercatch (Exception)also catches them — prefer the specific types when you want to distinguish load failures from save failures.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
PsdLoadException on a file that opens fine in other tools | The input is not a valid PSD/PSB document, or uses a feature this FOSS build’s parser does not recognize | Confirm the file is a genuine PSD/PSB document; report unsupported features separately from load failures |
PsdSaveException when writing to a stream | The destination stream may not be writable or may have been disposed already | Confirm the stream is open and writable before calling Save() |
FAQ
Does this library retry automatically after a load or save failure?
No. PsdLoadException and PsdSaveException are raised once and must be handled by the caller; there is no automatic retry.
Can I inspect the original cause of a wrapped exception?
Yes, when one is provided — both constructors accept an innerException parameter, accessible through the standard Exception.InnerException property.
API Reference Summary
| Class/Method | Description |
|---|---|
PsdLoadException(message) / PsdLoadException(message, innerException) | Thrown when a document cannot be loaded |
PsdSaveException(message) / PsdSaveException(message, innerException) | Thrown when a document cannot be saved |