Depends on the function....
If I'm making a site, when it's in debug mode I'll display exceptions on the website. If it's going live, I'll log the exceptions to a file.
But even then it doesn't help, take this PHP code as an example:
<?php
$mysqli = mysqli_connect('localhost','username','password','database');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
function selectUserByID($id){
global $mysqli;
$query = "SELECT * FROM users WHERE id = $id";
if ($result = mysqli_query($mysqli, $query)) {
while ($row = mysqli_fetch_assoc($result))
return $row;
}else{
//Query failed exception here
return null;
printf("Error: %s\n", mysqli_error($mysqli));
}
}
?>
Now, let's say we are gunna send a GET value to selectUserByID() and then output the full results
<?php
require_once("mysqli.php");
if(isset($_GET['id'])){
$user = selectUserByID($_GET['id']);
if($user != null){
$keys = array_keys($user);
foreach($keys as $key){
echo $user[$key].'</br>';
}
}
}
?>
Looks fine? Right? Well, wrong. This is open to MySQL injection. Passing a ' to it will trigger the " printf("Error: %s\n", mysqli_error($mysqli)); " in our mysqli page. This let's us know that the page is open to injection. Even if we commented out the stuff that shows the error, it would be obvious (since the output data will be messed).
The attack can then inject malicous mysql queries via the GET. The mysqli will execute the query and because it was executed successfuly, the exception is never triggered
A fix to the above function would be to add "$id = mysqli_real_escape_string($mysqli,$id);" Or better yet, switch too PDO/Mysqli via Objects.
So whilst exceptions can allow us to log/display errors and keep the page running, it doesn't stop this example. If you don't want to get hacked, you need to write good code and to never trust the user.