Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General


Thread Tools Rate Thread Display Modes
Old 05-09-2016, 02:25 AM   #1
Registered User
Join Date: Dec 2013
Location: Banglore
Posts: 336
Send a message via AIM to chinmay.sahoo Send a message via MSN to chinmay.sahoo
Arrow Replacing built-in PHP fatal errors with exceptions

Once we’re using exceptions, it’s a bit irritating that errors from PHP are reported as PHP 4-style errors rather than as exceptions. But it is possible to build a bridge from the old error-handling system to the new. Although this will not catch all errors (fatal runtime errors such as calling a nonexistent method on an object will not be reported), it will make error handling more consistent.

The first things we need are an exception class to distinguish the PHP errors from other exceptions and a simple error handler to receive a PHP error and throw an exception instead:

class ErrorFromPHPException extends Exception {}
function PHPErrorHandler($errno, $errstr, $errfile, $errline) {
throw new ErrorFromPHPException($errstr,$errno);

Now we can set the error handler. If we proceed to try to open a nonexistent file, we will get an exception instead of the old-fashioned error:

Growth on Height | No Addiction Powder | Step Up Height Increaser | Growth on Height
chinmay.sahoo is offline   Reply With Quote


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Importance of Php Development for Web Development tech.biztech Programming General 54 08-01-2018 01:18 PM
PHP introduction stevepatton PHP / mySQL 54 07-27-2018 06:24 PM
PHP project training in ahmedabad, live project training in php ahmedabad anantitsolution Post your ad here 13 07-20-2018 09:43 PM
Thinking of replacing and old well established site with new content driven php site kaptai2013 Search Engine Optimization 2 05-20-2018 08:22 AM
Explain the different types of errors in PHP. Broach India Programming General 7 04-10-2015 02:46 AM

All times are GMT -7. The time now is 02:04 PM.

Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.