473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 13638
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mage | last post by:
Hello, def error_msg(msg): sys.exit(msg) try: do_something() if value != my_wish: error_msg('Invalid input')
42
by: cody | last post by:
public DateTime Value { get { try { return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text), int.Parse(tbDay.Text)); } catch (FormatException)
7
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
7
by: Dan Bass | last post by:
In a somewhat complex application, I've developed plug-in architecture and am having a problem as to when to catch general exceptions for logging purposes. In each plug-in class library, for...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
1
by: Noor | last post by:
Hi all, I am trying to catch all types of exceptions from a app regardless of whether it is in debugger mode( VS development environment) or run the.exe file outside the IDE. My App...
7
by: ZorpiedoMan | last post by:
Well, I'm still wondering around in the "land of the lost exception"... It seems that controls that are bound to a class and the class throws an error in the SET method of the bound member, the...
5
by: Bry | last post by:
I've created a class that offers an enhanced way of handling fatal exceptions. The class allows the user to optionaly submit a http based anonymous error report to myself, and also records details...
6
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.