php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28033 try-catch doesnt really catch ?
Submitted: 2004-04-17 02:29 UTC Modified: 2004-04-17 03:46 UTC
From: phil at adigital dot com dot mx Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0RC1 OS: linux red hat
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: phil at adigital dot com dot mx
New email:
PHP Version: OS:

 

 [2004-04-17 02:29 UTC] phil at adigital dot com dot mx
Description:
------------
It seems that try-catch only catch the exception that USER program into its code with a throw...

I hope this is a transitional state, since the most usefull and interesting catches that you can get are definitively "WARNINGS" and "FATAL ERRORS" taht PHP itself can give. see example below

I hope all PHP functions (i-e- Zend 2 engine) will be able to catch WARNINGS and FATAL ERRORS somehow, or said on other words, that any PHP functions will use Throw *any exceptions*

Thx


Reproduce code:
---------------
error_reporting(E_ALL);

try 
{
  print $variable_not_set;

  // syntax error eval
  $toeval = "print \"Hola exec 1;";
  eval($toeval);
  $toeval = "print \$not_set_variable;";
  eval($toeval);

}
catch (Exception $exception) 
{
  echo "CATCHED EXCEPTION: ".$exception;
}



Expected result:
----------------
this is supposed to catch the warning of non existing variable, the syntax error of evaluated expresion and the warning of not set variable into evaluate expresion.

It doesn't catch anything !

(cf: Java does !)



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-17 03:46 UTC] derick@php.net
Expected behavior. Normal errors are NOT exceptions and will therefore not be caught. Only thrown exceptions (extended fromthe Exception class) will be real exceptions, all usually errors (E_WARNING, E_NOTICE and E_ERROR) will not (as they are not exceptions).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 01 13:00:01 2025 UTC