DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. PHP Error Listener

PHP Error Listener

Snippets Manager user avatar by
Snippets Manager
·
Nov. 17, 08 · Code Snippet
Like (0)
Save
Tweet
Share
973 Views

Join the DZone community and get the full member experience.

Join For Free
Error listener for PHP, shows simple errors as exceptions.


//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
class ErrorListener{
	static protected $listening = false;
	static protected $listeningExceptions = false;

	public static function start(){
		if(self::$listening)
			return;
		set_error_handler(array('ErrorListener', 'dispatcher'));
		self::$listening = true;
	}
	public static function stop(){
		if(!self::$listening)
			return;
		restore_error_handler();
		self::$listening = false;
	}
	public static function dispatcher($code, $message){
		throw new Exception($message, $code);
	}
	public static function setDefaultExceptionHandler($callback){
		if(self::$listeningExceptions)
			return;
		set_exception_handler($callback);
	}
	public static function restoreDefaultExceptionHandler(){
		if(!self::$listeningExceptions)
			return;
		restore_exception_handler();
	}
}
PHP

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 2023 Software Testing Trends: A Look Ahead at the Industry's Future
  • Kotlin Is More Fun Than Java And This Is a Big Deal
  • The Role of Data Governance in Data Strategy: Part II
  • How To Use Terraform to Provision an AWS EC2 Instance

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: