Error Handling
Use the Exception model to handle errors
3.8M Downloads / Month
Open Source MIT License
3.8M Downloads / Month
Open Source MIT License
Discover how to use the exception model of Intervention Image to catch and handle different types of er
If something goes wrong, Intervention Image throws exceptions. For this purpose, a structured hierarchy has been implemented.
All exceptions are extended from a container the container class Intervention\Image\Exceptions\ImageException. This makes it possible to
catch all errors in the library in general.
The container class is divided into two types: LogicException and RuntimeException indicating and operational failure or that the error can be
fixed by correcting the code.
These two types are each divided into further sub-branches. Adding the possibility to intercept every type of error in detail and respond accordingly.
ImageException
├── LogicException
│ ├── ArgumentException
│ │ └── InvalidArgumentException
│ ├── NotSupportedException
│ └── StateException
│
└── RuntimeException
├── MissingDependencyException
├── FilesystemException
│ ├── DirectoryNotFoundException
│ ├── StreamException
│ ├── FileNotFoundException
│ ├── FileNotReadableException
│ └── FileNotWritableException
└── DriverException
├── AnalyzerException
├── ModifierException
├── DecoderException
│ ├── ImageDecoderException
│ └── ColorDecoderException
└── EncoderException
Exceptions of type Intervention\Image\LogicException mean that the API was
not addressed correctly, i.e., there is an error in the end user's code. There
are further sub-types.
This exceptions are thrown when a argument passed does not match the expected format. For example, if a negative value is specified for an image width.
This type of exception indicates that something was requested that lacks general support. For example, when an image is to be converted to a color space that is not implemented for the driver.
This type of exception indicates that something is not in the correct state for the requested operation. For example when you try to decode an image but there are no decoders in the handler stack.
RuntimeException means operational failure. Usually occurs when something internal goes wrong. See the following sub-types for better understanding.
This exception indicates that a dependency is not been met. For example when you try to use the driver for Imagick but forgot to install the matching PHP extension.
This extension is thrown when something went wrong in the filesystem. This can have various causes. For example, a file cannot be read because it does not exist or there are no permissions to do so. Or a directory cannot be written to because it does not exist.
There is an exception type for each of these individual cases.
Intervention\Image\Exceptions\DirectoryNotFoundExceptionIntervention\Image\Exceptions\StreamExceptionIntervention\Image\Exceptions\FileNotFoundExceptionIntervention\Image\Exceptions\FileNotReadableExceptionIntervention\Image\Exceptions\FileNotWritableExceptionThis exception is thrown when the underlying image extension produces an error. It is divided into four sub-types, each dealing with a specific driver operation.
Intervention\Image\Exceptions\AnalyzerExceptionIntervention\Image\Exceptions\ModifierExceptionIntervention\Image\Exceptions\DecoderExceptionIntervention\Image\Exceptions\EncoderException