I try throw exception when there is no result in database, here is code:
try {
if (!$stmt->execute()) {
throw new ErrorExeption('there is no row with that id');
}
} catch (ErrorExeption $e) {
echo $e->getMessage();
}
So, when I paste wron Id I cant see the error message. What I am doing wrong?
Consider this:
try {
$stmt->execute();
if (!$row = $stmt->fetch(PDO::FETCH_ASSOC)) {
throw new ErrorExeption('there is no row with that id');
}
} catch (PDOException $e) {
echo $e->getMessage();
} catch (ErrorExeption $e) {
echo $e->getMessage();
}
Could you please consider to check the spelling on ErrorExeption
to ErrorException
?
Because I tried this on my local server, and the script can catch error message that we throw above.