|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27283 Exception not caught if more than two catch blocks are used
Submitted: 2004-02-16 21:09 UTC Modified: 2004-04-20 16:11 UTC
Avg. Score:5.0 ± 0.0
Reproduced:10 of 11 (90.9%)
Same Version:3 (30.0%)
Same OS:4 (40.0%)
From: benjcarson at digitaljunkies dot ca Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-03-15 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
6 + 32 = ?
Subscribe to this entry?

 [2004-02-16 21:09 UTC] benjcarson at digitaljunkies dot ca
If an exception is thrown within a try block and more than two catch blocks follow, the exception may not be caught.  If the exception matches either of the first two catch blocks then the exception will be caught.  However, if the exception does not match the first two catch blocks, it will skip any remaining catch blocks and remain uncaught.

In the code below, the exception is caught properly if the second catch block is commented out.  Once it is included again though, the exception is not caught.

Reproduce code:
class Ex1 extends Exception { }
class Ex2 extends Exception { }
class Ex3 extends Exception { }

try {
  throw new Ex3("Ex3");

} catch (Ex1 $e) {
  echo ("Ex1: " . $e->getMessage() ."\n");

} catch (Ex2 $e) {
  echo ("Ex2: " . $e->getMessage() ."\n");
} catch (Exception $e) {  // Note: trying to catch Ex3 also fails
  echo ("Exception: " . $e->getMessage() . "\n");

Expected result:
Execption: Ex3

Actual result:
Fatal error: Uncaught exception 'Ex3' with message 'Ex3' exception.php:8
Stack trace:
#0 {main}
  thrown in exception.php on line 8


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-06 14:04 UTC] benjcarson at digitaljunkies dot ca
For now we've had to use this workaround:

class Ex1 extends Exception { }
class Ex2 extends Exception { }
class Ex3 extends Exception { }

try {
  throw new Ex3("Ex3");

} catch (Exception $e) {

  if ($e instanceof Ex1) 
    echo ("Ex1: " . $e->getMessage() . "\n");
  else if ($e instanceof Ex2)
    echo ("Ex2: " . $e->getMessage() . "\n");
  else if ($e instanceof Ex3)
    echo ("Ex3: " . $e->getMessage() . "\n");
    echo ("Exception: " . $e->getMessage() . "\n");
 [2004-03-28 01:47 UTC] myle34 at hotmail dot com
Not only do I have the same problem, but when your code is executed several times, Apache crashes on Windows XP SP1 with Apache 2.0.48.

However, I have found that ALL exception related code crashes after several page refreshes. Additionally, the more complex the exception code, the fewer page refreshes it takes to crash.
 [2004-04-20 16:11 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Sep 25 07:01:23 2020 UTC