Is it good coding practice to always catch the base Exception class in a try catch?
try
{
//
// Piece of code
//
}
catch (CustomException $my_ex)
{
// Handle CustomExcepton
}
catch (Exception $other_exceptions)
{
// Handle all other exceptions
}
If so, why?
In PHP you can install a global exception handler.
When needed you can catch exceptions in your code, all unhandled exceptions go to the global exception handler. Depending on your strategie, you decide what to do.
Of course, when you decide to die, a clear error message and a log is appreciated.
In general, if you can recover from a exception, use a try .. catch block, otherwise let the global exception handler do his work, and do not recover.