Framework Docs Error Handling

Error Handling

The Error class installs PHP's global error, exception, and shutdown handlers during bootstrap. It adapts its behavior based on the DEBUG constant — showing a detailed trace in development and a clean error page in production.

Namespace: Wojo\Core\Error

Error Class

Method Signature Description
run() static run(): ?self Register all PHP error handlers and return the instance. Called once by bootstrap.
errorHandler() static errorHandler(int $code, string $msg, string $file, int $line): bool Installed via set_error_handler(). Converts PHP errors to exceptions; sends notices to the Debug panel.
exceptionHandler() static exceptionHandler(Throwable $error): void Installed via set_exception_handler(). Logs the exception, logs to Debug, and renders the error view.
shutdown() static shutdown(): void Registered via register_shutdown_function(). Catches fatal errors that the exception handler cannot.
notFoundHandler() static notFoundHandler(NotFoundException $e): never Called by controllers when a record is not found. Renders 404.tpl.php in production or error.tpl.php in debug mode.

NotFoundException

Throw NotFoundException inside a controller method when a requested record does not exist. The global exception handler catches it and calls Error::notFoundHandler() to render the 404 page.

PHP
use Wojo\Core\NotFoundException;

public function show(int $id): void
{
    $post = Database::Go()->select('posts')->where('id', $id)->first();

    if (!$post) {
        throw new NotFoundException(Language::get('INVALID_ID'));
    }

    $tpl->post     = $post;
    $tpl->template = 'post-detail';
}

Debug Mode vs. Production

Scenario DEBUG = true DEBUG = false
Unhandled exception Full stack trace rendered in error.tpl.php Generic "Something went wrong" page, error logged
PHP notice / deprecation Added to the Debug panel Silently swallowed (logged only)
NotFoundException Error message + file/line in error.tpl.php Clean 404.tpl.php page
Fatal (E_ERROR, E_PARSE) Exception trace via shutdown handler Clean error page, logged