当数据库中没有结果时,我尝试抛出异常,这是代码:
try {
if (!$stmt->execute()) {
throw new ErrorExeption('there is no row with that id');
}
} catch (ErrorExeption $e) {
echo $e->getMessage();
}
因此,当我粘贴wron ID时,我看不到错误消息。我做错了什么?
考虑一下:
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();
}
你能考虑检查一下ErrorExeption
到ErrorException
的拼写吗?
因为我在本地服务器上尝试过这个,并且脚本可以捕获我们上面抛出的错误消息。