In our code this week we have added a try/catch/throw forexceptions generated when connecting to a database. This isgreat. The question now is, how far should this be extended?Look through the rest of the code that we have in place. Towhat extent can we capture errors and throw exceptions? Should wecreate an exception class for every type of error? A classhierarchy of errors? Or should we have one catch all exception fordatabases errors? Or do nothing at all?
For example, look at the code below. All of the APIs can returnerrors. Prepare, execute, bind_results. How defensiveshould our code get? In the event of errors in these fragments whatshould we do? Obviously, we are not doing anything right now ...should we do something and if so how should we structure our codeto handle any detected errors?
$stmt = $db->prepare($query);
$stmt->execute();
$stmt->bind_result($bname, $summary);
//echo "<br/>Blogs Summary</p>";
while($stmt->fetch()) {
echo $bname." ".$summary."</p>";
}
In our code this week we have added a try/catch/throw for exceptions generated when connecting to a database. This is gr
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am