[php-src] Issue #11228: Can we support exclude some specific Exception when catch Exception?

From: Date: Thu, 11 May 2023 08:19:49 +0000
Subject: [php-src] Issue #11228: Can we support exclude some specific Exception when catch Exception?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244428@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11228 Author: gitHusband ### 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. 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; } } } ```

« previous php.bugs (#244428) next »