pear/pear_exception
PEAR_Exception provides a base exception class for PEAR-style PHP libraries, adding standardized error messaging, cause chaining, and improved debugging context. Useful for modernizing legacy PEAR code or integrating consistent exception handling across packages.
pear/pear_exception is a lightweight, PSR-3 compatible exception class that extends PHP’s native Exception and adds a structured getMessage() with contextual details (like error code, file, line, and optional debugInfo()). It’s primarily used in legacy or hybrid codebases that still leverage PEAR-style error handling or need a clean, standardized exception base. Start by requiring it via Composer (composer require pear/pear_exception) and extending it for domain-specific exceptions. First use case: replacing generic Exception with PEAR_Exception in legacy PEAR-based code to maintain consistency and preserve structured error data.
App_Exception extends PEAR_Exception, then subclass further (e.g., Validation_Exception, Database_Exception) to inject domain semantics.debugInfo() to redact sensitive data (e.g., passwords) or include context (e.g., user ID, request ID) without exposing internals in logs.set_error_handler() that converts PHP errors to exceptions (e.g., set_error_handler(['PEAR_Exception', 'handleError'])), enabling modern try/catch for otherwise fatal errors.PEAR_ErrorStack or PEAR_Error by mapping error codes to PEAR_Exception instances during migration from older frameworks (e.g., legacy Horde, PHPUnit < 9).symfony/serializer’s exception helpers or roll your own extends Exception if forward compatibility is critical.PEAR_Config or legacy include_path hacks).getMessage() Override: getMessage() returns a formatted string (code + message), unlike native Exception. If logging tools expect raw messages, extract via ->getMessage() and parse or use getPrevious()/getTrace() carefully.ERROR_RETURN Quirk: This package was designed for PEAR’s error-return conventions (PEAR::raiseError() returns an error object, not throw). Use PEAR_Exception::raiseError() for non-throwing usage, but prefer exceptions for type safety in modern code.Error class (non-Exception errors) to ensure no regressions.League\ErrorHandler or custom exceptions).How can I help you explore Laravel packages today?