Issue
Is it possible in nested try and catch to catch the same exception in all blocks?
For example:
try{
try{
throw new Exception("exception");
}
catch (Exception $exception)
{
echo "inner catch fires";
}
}
catch (Exception $exception)
{
echo "outer catch fires";
}
For such scenario the result would be "the inner catch fires, so the outer catch fires, too"
Solution
Yes you can do that by throwing an exception from inner catch. Such as:
try {
try {
throw new Exception('exception');
} catch (Exception $exception) {
echo 'inner catch fires';
throw $exception;
}
} catch (Exception $exception) {
echo 'outer catch fires';
}
Answered By - Ben
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.