{"id":19961116,"url":"https://github.com/formapro/universalerrorcatcher","last_synced_at":"2025-05-03T22:30:33.257Z","repository":{"id":1490911,"uuid":"1740115","full_name":"formapro/UniversalErrorCatcher","owner":"formapro","description":"Easy way to catch and handle all php errors and exceptions.","archived":false,"fork":false,"pushed_at":"2012-09-25T07:11:13.000Z","size":250,"stargazers_count":21,"open_issues_count":6,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-31T15:23:57.672Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formapro.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-05-12T20:00:39.000Z","updated_at":"2024-05-17T22:14:10.000Z","dependencies_parsed_at":"2022-08-16T13:25:11.635Z","dependency_job_id":null,"html_url":"https://github.com/formapro/UniversalErrorCatcher","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FUniversalErrorCatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FUniversalErrorCatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FUniversalErrorCatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formapro%2FUniversalErrorCatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formapro","download_url":"https://codeload.github.com/formapro/UniversalErrorCatcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224374785,"owners_count":17300691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T02:06:25.755Z","updated_at":"2024-11-13T02:06:26.435Z","avatar_url":"https://github.com/formapro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Universal error catcher [![Build Status](https://secure.travis-ci.org/formapro/UniversalErrorCatcher.png?branch=master)](http://travis-ci.org/formapro/UniversalErrorCatcher)\n\n## Overview\n\nIt wraps errors and exception handling logic. \nAny exceptions or errors (even parse and fatal ones) are handled in the same way. \n\nThe lib also provides two custom exceptions: \n\n* `FatalErrorException` - fatal errors i.e. `E_ERROR`, `E_PARSE`, `E_CORE_ERROR`, `E_COMPILE_ERROR`\n* `SuppressedErrorException` - recoverable errors which comes from the code under `@`\n\nIt is completely covered with phpunit tests.\n\n## Instalation\n\n[Composer](http://getcomposer.org/) is a prefered way to install it.\n\n```bash\nphp composer.phar require fp/universal-error-catcher\n```\n\nWhen you are asked for a version constraint, type * and hit enter.\n\n## Quick tour\n \nThe example shows the simplest way of sanding an email on each error. \n\n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n\n    $catcher-\u003eregisterCallback(function(Exception $e) {\n      $to = 'admin@example.com';\n      $subject = 'Error: '.$e-\u003egetMessage();\n      $body = (string) $e;\n\n      mail($to, $subject, $body);\n    });\n\n    $catcher-\u003estart();\n\n    // after the start method is called everything is under your control.\n```\n\n### Fatal errors.\n\nLet's imagine we try to call a method which does not exist. In this situation php will raise a fatal error. \n\n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n\n    $catcher-\u003eregisterCallback(function(Exception $e) {\n      $e instanceof FatalErrorException //true\n    });\n\n    $catcher-\u003estart();\n\n    $anObject-\u003enotExistMethod();\n\n```\n\nOr the other situation when we run out of memory. In this case the catcher will gladly free some resorved memory for us. \n\n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n\n    $catcher-\u003eregisterCallback(function(Exception $e) {\n      $e instanceof FatalErrorException //true\n    });\n\n    $catcher-\u003estart();\n\n    ini_set('memory_limit', '1K');\n\n    str_repeat('foobar', PHP_INT_MAX);\n```\n\n### Recoverable errors:\n\nBy default php errors (warnings and so on) wouldn't be thrown but passed to callback in background.\n\n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n\n    $catcher-\u003eregisterCallback(function(Exception $e) {\n        $e instanceof ErrorException //true\n    });\n\n    $catcher-\u003estart();\n    \n    echo $undefinedVariable;\n    \n    echo 'the script continue to work. This message will be outputed';\n```\n\nYou can change this by converting all errors to exception. just set `setThrowRecoverableErrors` to true.\n\n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n    $catcher-\u003esetThrowRecoverableErrors(true); // false by default\n\n    $catcher-\u003eregisterCallback(function(Exception $e) {\n        $e instanceof ErrorException //true\n    });\n\n    $catcher-\u003estart();\n    \n    echo $undefinedVariable;\n    \n    echo 'the exception is throw. It will never be outputed';\n```\n\nThe errors behaind `@` (i.e suppressed) are also caught. \nChange `setThrowSuppressedErrors` to true if you want throw them.\n \n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n \n    $catcher-\u003eregisterCallback(function(Exception $e) {\n        $e instanceof SuppressedErrorException //true\n    });\n \n    $catcher-\u003estart();\n\n    @trigger_error('supressed warning', E_USER_WARNING);\n     \n    echo 'the script continue to work. This message will be outputed';\n```\n \n### Exceptions:\n \nAny not caught exceptions will be passed to you: \n \n```php\n\u003c?php\n    $catcher = new UniversalErrorCatcher_Catcher();\n \n    $catcher-\u003eregisterCallback(function(Exception $e) {\n        $e instanceof LogicException //true\n    });\n \n    $catcher-\u003estart();\n \n    throw new LogicException('something strange happened. I am scared.');\n     \n    echo 'the exception is throw. It will never be outputed';\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformapro%2Funiversalerrorcatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformapro%2Funiversalerrorcatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformapro%2Funiversalerrorcatcher/lists"}