ExtensionError
The error a call into an extension throws when the extension's code crashes. An extension is code that runs in a sandbox beside your program, such as the built-in Novis\Image and Novis\Intl. When that code stops on a bug of its own, your call throws ExtensionError. It is a RuntimeError, so a catch (RuntimeError $e) catches it too.
The crash stays inside the sandbox. Your request goes on, and the next call to the same extension works again. So you can catch the error and show the page without the part that failed.
An extension also reports ordinary problems, and those throw other classes. Bad input throws LogicError, and text it could not read throws ParseError. A call that uses more time or memory than the request may use is not an error you can catch: it ends the request.
The example below shows a page of uploads that keeps working when one thumbnail cannot be made.
Examples
A page that stays up when an extension crashes
<?nvs// Shows how a page keeps working when code in an extension crashes.
class Thumbnails{ // This method replaces a call into an image extension. For one file, it // throws the same error that a crashed extension throws. public static function make(string $name): string { if ($name == 'broken.png') { throw new ExtensionError('the extension stopped while it read ' . $name); } return $name . ' at 200x200'; }}
array<string> $uploads = ['cat.png', 'broken.png', 'dog.png'];foreach ($uploads as string $name) { try { echo Thumbnails::make($name), "\n"; } catch (ExtensionError $crashed) { // The page shows this file without a thumbnail and goes on with the next one. echo $name, ' has no thumbnail: ', $crashed->message, "\n"; }}cat.png at 200x200broken.png has no thumbnail: the extension stopped while it read broken.pngdog.png at 200x200