-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Closed as not planned
Closed as not planned
Copy link
Description
Description
Hi,
Can we support exclude some specific Exception when catch Exception?
I don't want to catch RuntimeException in Child catching block, but catch RuntimeException in Parent catching block.
(NOTE that RuntimeException just an example, not real)
For now, I can handle it like test
and test1
method.
But can we support any other more concise approach? such as test2
method?
For example,
<?php
class Example
{
public function test()
{
// Parent catching
try {
// Child catching
try {
// Throw Exception
} catch (\Exception $e) {
// exclude \RuntimeException and re-throw it
if ($e instanceof \RuntimeException)
throw $e;
return false;
}
} catch (\RuntimeException $e) {
return true;
}
}
public function test1()
{
// Parent catching
try {
try {
// Throw Exception
} catch (\RuntimeException $e) {
// exclude \RuntimeException and re-throw it
throw $e;
} catch (\Exception $e) {
return false;
}
} catch (\RuntimeException $e) {
return true;
}
}
public function test2()
{
// Parent catching
try {
// Child catching
try {
// Throw Exception
}
// catch \Exception but exclude \RuntimeException
catch (\Exception && !\RuntimeException $e) {
return false;
}
} catch (\RuntimeException $e) {
return true;
}
}
}