try {
// call a success/error/progress handler
} catch (Throwable $e) { // For PHP 7
// handle $e
} catch (Exception $e) { // For PHP 5
// handle $e
}
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division durch Null.');
}
return 1/$x;
}
try {
echo inverse(5) . "
";
echo inverse(0) . "
";
} catch (Exception $e) {
echo 'Exception abgefangen: ', $e->getMessage(), "
";
}
// Ausführung fortsetzen
echo "Hallo Welt
";
?>
public function search(Request $request)
{
try {
$user = $this->userService->search($request->input('user_id'));
} catch (ModelNotFoundException $exception) {
return back()->withError($exception->getMessage())->withInput();
}
return view('users.search', compact('user'));
}