471,309 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,309 software developers and data experts.

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

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.

Jul 17 '05 #1
1 13491
Mike wrote:
How do I get PHP to catch fatal
errors?


You can only catch non-fatal errors. Fatal errors will always stop the
script because of their severity. Compare it with Java, which will stop
compiling when fatal errors occur...
JW

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mage | last post: by
42 posts views Thread by cody | last post: by
7 posts views Thread by Dan Bass | last post: by
40 posts views Thread by Kevin Yu | last post: by
1 post views Thread by Noor | last post: by
7 posts views Thread by ZorpiedoMan | last post: by
5 posts views Thread by Bry | last post: by
6 posts views Thread by Steve | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.