Suppose to have a PHP code inside a try...catch block. Suppose that inside catch you would like to do something (i.e. sending email) that could potentially fail and throw a new exception.
try {
// something bad happens
throw new Exception('Exception 1');
}
catch(Exception $e) {
// something bad happens also here
throw new Exception('Exception 2');
}
What is the correct (best) way to handle exceptions inside catch block?
$db = new PDO();throws aPDOException, if you want to catch those, you wrap that line in a try-catch. Nothing else. If a specific method can throw different exceptions, and you want to handle them differently, you can writetry{} catch (MinorException $e){}catch(Exception $e){//all other exceptions}