How do I get PHP5's Exception Handling to catch a fatal error?

From: Mike (n00spam_at_comcast.net)
Date: 02/27/05


Date: 27 Feb 2005 11:42:54 -0800

Last weekend I decided to install
  Apache 2.0.53-win32-x86-no_ssl
  PHP 5.0.3
  Smarty 2.6.7
  MySQL essential-4.1.10-win32

I have Apache up (Port 80 blocked at the router and firewall!) and I
have got
Smarty working. I haven't got around to installing MySQL. I am now in
chapter 8 'Error and Exception Handling' of
"Beginning PHP 5 and MySQL: From Novice to Professional", by W. Jason
Gilmore,
pub. Apress. I tried example Listing 8-1. Raising an Exception:
  <?php
  //Boilerplate
  require('Smarty.class.php');
    $smarty = new Smarty;

    $smarty->template_dir='C:\php5\includes\smarty\templates\\';
    $smarty->compile_dir='C:\php5\includes\smarty\templates_c\\';
    $smarty->config_dir='C:\php5\includes\smarty\configs\\';
    $smarty->cache_dir='C:\php5\includes\smarty\cache\\';

  //Example 8.1
  try {
    $conn = mysql_connect("localhost1","webuser","secret");
    if (! $conn) {
      throw new Exception("Could not connect");
    }
  }
  catch (Exception $e
) {
    echo "Error (File: ".$e->getFile().", line ".$e->getLine()."):
".$e->getMessage();
  }
  ?>

Note that in the book, on the echo statement, the $e-> was missing from
the
getFile(). I went ahead and added it.

Cutting to the chase, when I ran the above nothing happened. I checked
the
log and saw the following:

  [27-Feb-2005 11:33:59] PHP Fatal error: Call to undefined function
mysql_connect() in
  C:\Program Files\Apache Group\Apache2\htdocs\example81.php on line 13

I commented out everything in the try block except the throw statement
and
reran. It worked as expected. How do I get PHP to catch fatal errors?

BTW, error_reporting = E_ALL

--Thank you,
--Mike Jr.



Relevant Pages

  • RE: [PHP] Xampp question, pretty much 0T
    ... I suggest you look into VMWare. ... versions (player, server, etc) if you don't want Workstation (which I ... [PHP] Xampp question, pretty much 0T ... recommended it to me when I asked for an easy install of AMP. ...
    (php.general)
  • HOWTO: FreeTDS for Newbies (almost complete)
    ... One way to do that is to install FreeTDS, recompile PHP, ... You can go to freetds.org and install the RPMs on Unix or Linux ...
    (comp.lang.php)
  • Re: [SLE] updating to PHP5
    ... while running PHP 5 for my stuff. ... managed by SuSE staff where you can download latest apache with all ... SLES 9 doesn't need PHP for its default configuration. ... Thus, it seems possible to remove PHP4, install a new Apache instance, PHP5 ...
    (SuSE)
  • RE: Mea Culpa, Ive killed OWA/RWW/Other stuff with NET STOP
    ... the SSL port to the new site, once that was deleted, I was able to ... Perhaps posting my config, as you requested, will help answer this question: ... available - it's a PHP intranet/extranet application, ... >>I was trying to install PHP manually, ...
    (microsoft.public.windows.server.sbs)
  • Re: PHP Tutorials
    ... >> In this tutorial we assume that your server has activated support for PHP ... install a web server locally (not just Apache). ...
    (comp.lang.php)