-
-
Notifications
You must be signed in to change notification settings - Fork 0
Exceptions
Muhammet Şafak edited this page Jun 11, 2026
·
1 revision
All exceptions live in the InitPHP\Views\Exceptions namespace and implement
the marker interface ViewExceptionInterface, which extends Throwable. A
single catch (ViewExceptionInterface $e) therefore handles every failure the
package can raise.
Throwable
├── RuntimeException
│ └── ViewException implements ViewExceptionInterface
│ └── ViewAdapterException
└── InvalidArgumentException
└── ViewInvalidArgumentException implements ViewExceptionInterface
| Exception | Extends | Thrown when |
|---|---|---|
ViewException |
RuntimeException |
The facade is used before an adapter is registered; a Pure PHP view file is missing or resolves outside the view directory; an engine fails at render time. |
ViewAdapterException |
ViewException |
View::via() receives an adapter that does not exist, does not implement ViewAdapterInterface, or cannot be constructed without arguments. |
ViewInvalidArgumentException |
InvalidArgumentException |
A view or cache directory passed to an adapter constructor does not exist. |
Because ViewAdapterException extends ViewException, catching ViewException
also catches adapter-registration failures.
use InitPHP\Views\Exceptions\ViewExceptionInterface;
try {
echo view('dashboard', $data);
} catch (ViewExceptionInterface $e) {
// Any InitPHP Views failure lands here.
error_log($e->getMessage());
http_response_code(500);
echo 'The page could not be rendered.';
}Because the concrete classes also extend the native SPL exceptions, you can be as specific as you like:
use InitPHP\Views\Exceptions\ViewException;
use InitPHP\Views\Exceptions\ViewInvalidArgumentException;
try {
View::via(new PurePHPAdapter('/path/that/does/not/exist'));
} catch (ViewInvalidArgumentException $e) {
// bad directory at construction time
}
try {
echo view('missing-template');
} catch (ViewException $e) {
// missing view, path escape, or no adapter registered
}// No adapter registered yet → ViewException
view('home');
// Unknown adapter class → ViewAdapterException
View::via('App\\View\\NoSuchAdapter');
// Adapter class needs constructor arguments → ViewAdapterException
View::via(PurePHPAdapter::class);
// Class does not implement the interface → ViewAdapterException
View::via(stdClass::class);
// Missing view directory → ViewInvalidArgumentException
new PurePHPAdapter(__DIR__ . '/nope');
// Missing view file (Pure PHP) → ViewException
view('does/not/exist');
// Path traversal (Pure PHP) → ViewException
view('../secret');When you write a custom adapter, reuse these types so callers can handle your failures the same way:
-
ViewExceptionfor runtime problems (missing template, engine error); -
ViewInvalidArgumentExceptionfor invalid constructor arguments.
- API Reference
- The View Facade & Helper — which calls raise what.
initphp/views · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Adapters
Reference
Guides
Other