You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to throw an exception in a controller method and catch that in the dispatcher/router? Controller methods are called in the Dispatcher using call_user_func_array, which doesn't allow for catching exceptions.
If not, how else would you return early from a method?
classMyController {
publicfunctionanyIndex() {
$this->checkAccess('edit');
}
privatefunctioncheckAccess($permission) {
if ($userPermission != $permission) thrownewException("You don't have permission", 401);
}
}
The text was updated successfully, but these errors were encountered:
Is it possible to throw an exception in a controller method and catch that in the dispatcher/router? Controller methods are called in the
Dispatcher
usingcall_user_func_array
, which doesn't allow for catching exceptions.If not, how else would you return early from a method?
The text was updated successfully, but these errors were encountered: