php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41468 Exception is not catched in try-catch block in some environment
Submitted: 2007-05-23 08:42 UTC Modified: 2007-05-23 11:29 UTC
From: aleboo at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: aleboo at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-23 08:42 UTC] aleboo at gmail dot com
Description:
------------
Problem appears in try-catch block in some environment.
When some code throws exception and there is no more any code
right after throwing code in try-catchh block, then exception
is not catched and it falls to system. Other, upper level try-catch
blocks can't catch it too. Not sure about PHP version - it works on Windows with 5.2.0, it was working on Linux with 5.1.x version, but now it not working. Introducing die(), or break in the end of internal part of try-catch blocks sloves the problem, and exception is handled correcty, but it is offcourse workaround.


Reproduce code:
---------------
class Test{
	public function doTest(){
   		try{
   			throw new Exception( "test exception" );
   			// with break or die() here code will work!
   		}catch( Exception $ex ){
   			return "exception catched";
   		}
		return "ok";
	}
}
$testObj = new Test();
$content = $testObj->doTest();
echo( $content );

Expected result:
----------------
"exception catched" text

Actual result:
--------------
Fatal error: Uncaught exception 'Exception' with message 'test exception' in /path-to-test-file-dir/test.php:5 Stack trace: #0 /path-to-test-file-dir/test.php(14): Test->doTest() #1 {main} thrown in /path-to-test-file-dir/test.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-23 10:30 UTC] scottmac@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

I can't reproduce this locally with your test case.
 [2007-05-23 10:42 UTC] aleboo at gmail dot com
Currently situation is like:
I told my hosters (who originally suggested me to create bug report on bugs.php.net) that it is possible that problem is with optimizers, not with PHP by it self. After 2 hours everything start working fine, but they didnt reply me about theyr actions, so I am don't really know for now what heppened. In my testing environment (I also asked some my friends to test this case too) everything was allright. So, I think, my hosting provider fixed it silently but didnt inform me ( well, I was angry a little :? ). So, it may be still some bug with optimizer, but I can't provide any info, because has no data about hosting configuration details and how did they fixed it. Sorry, for wrong alarm, but I simply forgot about optimizers.
 [2007-05-23 11:29 UTC] scottmac@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC