calgamo / exception
exception hierarchy for calgamo framework
Installs: 6 629
Dependents: 9
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- ext-json: *
- calgamo/collection: ~0.7
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.3.0
This package is auto-updated.
Last update: 2019-11-19 04:29:12 UTC
README
Description
Calgamo/Exception is a library of exceptions. It provides yet another exception class hierarchy.
Class Hierarchy
\Exception
|
+-- CalgamoException
|
+--[Package]Logic
| |
| +-- PhpErrorException
|
+--[Package]Runtime
|
+-- ClassNotFoundException
|
+-- HttpStatusException
|
+-- InterfaceNotFoundException
|
+-- InvalidArgumentException
|
+-- PhpParseException
Note
- [MUST]You MUST NOT catch Logic Exceptions
- [MUST]You MUST catch Runtime Exceptions
Interface Hierarchy
\Throwable
|
+-- CalgamoExceptionInterface
|
+--[Package]Logic
| |
| +-- LogicExceptionInterface
|
+--[Package]Runtime
|
+-- BusinessExceptionInterface
|
+-- ConfigExceptionInterface
|
+-- RuntimeExceptionInterface
Note
- You can catch exceptions by interface, instead of catching by concrete exception class names.
try{ doSomething(); } catch(BusinessExceptionInterface $e) { // This typically means recoverable error, so you can process the exception and continue the procedure. } catch(RuntimeExceptionInterface $e) { // This typically means fatal error, so you should report the situation(my be logs) and abort the procedure. }
Back Traces
Every CalgamoException objects have own backtraces. So you can trace the call history by calling CalgamoException#getBackTraceList() method.
try{ doSomething(); } catch(CalgamoException $e) { foreach($e->getBackTraceList() as $trace){ // $trace is always instance of BacktraceItem $file = $trace->getFile(); $line = $trace->getLine(); $class = $trace->getClass(); $type = $trace->getType(); $function = $trace->getFunction(); echo "{$class}{$type}{$function} called at {$file}/{$line}" . PHP_EOL; }); }
Requirement
PHP 7.1 or later
Installing calgamo/exception
The recommended way to install calgamo/exception is through Composer.
composer require calgamo/exception
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.