Skip to content

ch12_exceptions

Daniel Samson edited this page Mar 7, 2025 · 3 revisions

TeensyPHP provides with an TeensyPHPException class that you can use to throw errors in your application.

use TeensyPHP\Exceptions\TeensyPHPException;
//
throw new TeensyPHPException("Error message", 500);
TeensyPHPException::throwNotFound();     // 404
TeensyPHPException::throwBadRequest();   // 400
TeensyPHPException::throwUnauthorized(); // 403

By default, when no arguments are provided, the error message is "Internal Server Error" and the status code is 500.

Clone this wiki locally