<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: User Errors in PHP</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Sun, 08 Nov 2009 18:39:36 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Pests</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1840</link>
		<dc:creator>Pests</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1840</guid>
		<description>&lt;p&gt;Thanks for the info. Never realized it could be used like that, and wondered why some applications used a method similar to that.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Thanks for the info. Never realized it could be used like that, and wondered why some applications used a method similar to that.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Knowles</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1841</link>
		<dc:creator>Alan Knowles</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1841</guid>
		<description>&lt;p&gt;I generally only use this for programming errors, in conjunction with the xdebug, extension (which does backtraces for you), it is a very usefull tool.&lt;/p&gt;

&lt;p&gt;It however gets very messy for managing program flow errors, having to  use @ and the $error_msg variable dont make for very readable code. Exceptions (PHP5) or PEAR::Error (PHP4) are better suited to that.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I generally only use this for programming errors, in conjunction with the xdebug, extension (which does backtraces for you), it is a very usefull tool.</p>
<p>It however gets very messy for managing program flow errors, having to  use @ and the $error_msg variable dont make for very readable code. Exceptions (PHP5) or PEAR::Error (PHP4) are better suited to that.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Maarten Manders</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1842</link>
		<dc:creator>Maarten Manders</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1842</guid>
		<description>&lt;p&gt;When using PHP 5 you should definately use exceptions instead of killing your application (die, trigger_error, ...).&lt;/p&gt;

&lt;p&gt;Basically every error should be thrown, no matter whether it&#039;s fatal or not. This way it&#039;s the code&#039;s client&#039;s decision if and where to catch it, wheter it&#039;s fatal and what to do with it.&lt;/p&gt;

&lt;p&gt;Who knows, maybe your mysql connection error could be recovered from by using an alternate server. Too bad the application would already be stone-dead after the first attempt. :)&lt;/p&gt;

&lt;p&gt;Then again you could use E_USER_WARNING or E_USER_NOTICE but without a custom error handler your client code would miss those errors.&lt;/p&gt;

&lt;p&gt;In my opinion trigger_error only goes well with very simple functional applications.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>When using PHP 5 you should definately use exceptions instead of killing your application (die, trigger_error, &#8230;).</p>
<p>Basically every error should be thrown, no matter whether it&#8217;s fatal or not. This way it&#8217;s the code&#8217;s client&#8217;s decision if and where to catch it, wheter it&#8217;s fatal and what to do with it.</p>
<p>Who knows, maybe your mysql connection error could be recovered from by using an alternate server. Too bad the application would already be stone-dead after the first attempt. :)</p>
<p>Then again you could use E_USER_WARNING or E_USER_NOTICE but without a custom error handler your client code would miss those errors.</p>
<p>In my opinion trigger_error only goes well with very simple functional applications.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: jnunemaker</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1843</link>
		<dc:creator>jnunemaker</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1843</guid>
		<description>&lt;p&gt;I&#039;ve never really looked into trigger_error; I guess now I will. Thanks for the article.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I&#8217;ve never really looked into trigger_error; I guess now I will. Thanks for the article.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: martinpav</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1844</link>
		<dc:creator>martinpav</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1844</guid>
		<description>&lt;p&gt;Check also function set_error_handler(). You can define your own function (or class) to handle errors. For example i use it for storing errors and also for email notification if FATAL error ocure. It also backtrace all function calls.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Check also function set_error_handler(). You can define your own function (or class) to handle errors. For example i use it for storing errors and also for email notification if FATAL error ocure. It also backtrace all function calls.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: bigduke</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1845</link>
		<dc:creator>bigduke</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1845</guid>
		<description>&lt;p&gt;wheee! another function added to my growing &quot;mental&quot; repository of PHP functions. Since I&#039;m making that jump from intermediate to advanced transition and learning the techniques to do so this is defeinitely going to be used for better error handling.&lt;br /&gt;
Nice post Thomas!&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>wheee! another function added to my growing &#8220;mental&#8221; repository of PHP functions. Since I&#8217;m making that jump from intermediate to advanced transition and learning the techniques to do so this is defeinitely going to be used for better error handling.<br />
Nice post Thomas!</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mmj</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1846</link>
		<dc:creator>mmj</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1846</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;When using PHP 5 you should definately use exceptions instead of killing your application&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;For every exception that is thrown, it either has to be caught, or generate an uncaught exception error.&lt;/p&gt;

&lt;p&gt;If it is caught, you still have the problem of deciding what to do when the error is caught.  Wouldn&#039;t you agree?  &lt;/p&gt;

&lt;p&gt;Obviously, if you can recover from the situation you wouldn&#039;t have to exit or use trigger_error.  However, if it&#039;s unrecoverable, what do you do when you catch the exception?  Do you display an error message to the screen or do you log the error?  Exception handling doesn&#039;t define what to do when an exception is caught, it just provides a way of catching an exception.  If you are on a live server, you don&#039;t want to display a diagnostic error message, which will reveal a lot about your application, to the public.  You want it to be quietly logged.  However, if you are on a testing server, then having diagnostic information shown on screen is desirable.&lt;/p&gt;

&lt;p&gt;Consider the following code:&lt;/p&gt;

&lt;code&gt;
try 
{
	$error = &#039;Always throw this error&#039;;
	throw new Exception($error);

	// Code following an exception is not executed.
	echo &#039;Never executed&#039;;

} 
catch (Exception $e)
{
	echo &#039;Caught exception: &#039;,  $e-&gt;getMessage(), &quot;\n&quot;;
}&lt;/code&gt;&lt;p&gt;&lt;br /&gt;
When the exception is caught, all that is done is an error message is displayed on screen.  If we replaced &#039;echo&#039; with &#039;trigger_error&#039;, then we could use PHP&#039;s error handling to decide what to do with the error.  It&#039;s easy to define custom error handling with &#039;set_error_handler&#039;.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<p>When using PHP 5 you should definately use exceptions instead of killing your application</p>
</blockquote>
</p><p>For every exception that is thrown, it either has to be caught, or generate an uncaught exception error.</p>
<p>If it is caught, you still have the problem of deciding what to do when the error is caught.  Wouldn&#8217;t you agree?  </p>
<p>Obviously, if you can recover from the situation you wouldn&#8217;t have to exit or use trigger_error.  However, if it&#8217;s unrecoverable, what do you do when you catch the exception?  Do you display an error message to the screen or do you log the error?  Exception handling doesn&#8217;t define what to do when an exception is caught, it just provides a way of catching an exception.  If you are on a live server, you don&#8217;t want to display a diagnostic error message, which will reveal a lot about your application, to the public.  You want it to be quietly logged.  However, if you are on a testing server, then having diagnostic information shown on screen is desirable.</p>
<p>Consider the following code:</p>
<p><code>
try 
{
	$error = 'Always throw this error';
	throw new Exception($error);

	// Code following an exception is not executed.
	echo 'Never executed';

} 
catch (Exception $e)
{
	echo 'Caught exception: ',  $e->getMessage(), "\n";
}</code>
</p><p>
When the exception is caught, all that is done is an error message is displayed on screen.  If we replaced &#8216;echo&#8217; with &#8216;trigger_error&#8217;, then we could use PHP&#8217;s error handling to decide what to do with the error.  It&#8217;s easy to define custom error handling with &#8217;set_error_handler&#8217;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: seanf</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1847</link>
		<dc:creator>seanf</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1847</guid>
		<description>&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;When the exception is caught, all that is done is an error message is displayed on screen&lt;/p&gt;&lt;/blockquote&gt;In your trivial example yes&lt;/p&gt;

&lt;p&gt;The power of exceptions is, as Maarten Manders said, to be able to recover from the exceptional behaviour that has occurred.  To use his example, you can catch whatever exception is thrown when a connection can&#039;t be established to the MySQL server.  To recover from the exception you could use a cached version of the data, connect to another server or something else.  However, if you know your application can&#039;t recover after a failed attempt to connect to the MySQL server then you can leave the exception to be caught with a custom exception handler (see &lt;a href=&quot;http://uk.php.net/manual/en/function.set-exception-handler.php&quot;&gt;set_exception_handler()&lt;/a&gt;) and log it, email it, show a general message or a debug page or anything else&lt;/p&gt;

&lt;p&gt;Sean :)&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
<blockquote>
<p>When the exception is caught, all that is done is an error message is displayed on screen</p>
</blockquote>
</p><p>In your trivial example yes</p>
<p>The power of exceptions is, as Maarten Manders said, to be able to recover from the exceptional behaviour that has occurred.  To use his example, you can catch whatever exception is thrown when a connection can&#8217;t be established to the MySQL server.  To recover from the exception you could use a cached version of the data, connect to another server or something else.  However, if you know your application can&#8217;t recover after a failed attempt to connect to the MySQL server then you can leave the exception to be caught with a custom exception handler (see <a href="http://uk.php.net/manual/en/function.set-exception-handler.php">set_exception_handler()</a>) and log it, email it, show a general message or a debug page or anything else</p>
<p>Sean :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: WebDevGuy</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1848</link>
		<dc:creator>WebDevGuy</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1848</guid>
		<description>&lt;p&gt;I&#039;d love to see how &quot;martinpav&quot;, or anyone else fo rthat matter, writes &amp; implements custom error handling that emails you when certain erros occur.  Goo idea for an article?&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I&#8217;d love to see how &#8220;martinpav&#8221;, or anyone else fo rthat matter, writes &#038; implements custom error handling that emails you when certain erros occur.  Goo idea for an article?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: lastcraft</title>
		<link>http://www.sitepoint.com/blogs/2005/02/23/user-errors-in-php/comment-page-1/#comment-1849</link>
		<dc:creator>lastcraft</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">870631339#comment-1849</guid>
		<description>&lt;p&gt;One tip. If you throw an error in a method, don&#039;t forget to return straight afterwoods. trigger_error() won&#039;t terminate your code if someone has installed a custom error handler and will run on and cause additional damage.&lt;/p&gt;

&lt;p&gt;yours, Marcus&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>One tip. If you throw an error in a method, don&#8217;t forget to return straight afterwoods. trigger_error() won&#8217;t terminate your code if someone has installed a custom error handler and will run on and cause additional damage.</p>
<p>yours, Marcus</p>]]></content:encoded>
	</item>
</channel>
</rss>
