PHP code example of hgh / exception-handler

1. Go to this page and download the library: Download hgh/exception-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hgh / exception-handler example snippets

  
/**  
* Class SampleException  
*/  
class SampleException extends BaseException implements ShouldPublish, ErrorInterface {  
}  
$exception = new SampleException("SampleException");  
  
$exceptionHandler = new ExceptionHandler($exception);  
$exception = $exceptionHandler->handle(); // The result will be SampleException class
  
\HGh\Handlers\Exception\Facades\Exception::handle($exception); // The result will be SampleException class
  
/**  
* Class AnotherSampleException  
*/  
class AnotherSampleException extends BaseException implements WarningInterface {  
}  
$exception = new AnotherSampleException("AnotherSampleException");  
$exception = \HGh\Handlers\Exception\Facades\Exception::handle($exception); // The result will UnexpectedException  
  
/**  
* Class SampleException  
*/  
class SampleException extends BaseException implements ShouldPublish, ErrorInterface {  
}  
$exception = new SampleException("SampleException");

use HGh\Handlers\Exception\Services\ExceptionLogger;$filePath = "/tmp/logs";  
$exceptionLogger = new ExceptionLogger($filePath);  
$exceptionLogger->log($exception);  
  
\HGh\Handlers\Exception\Facades\Exception::log($exception, $filePath);  

/**  
 * This class is a facade to all exception actions 
 * PHP version >= 7.0
 * 
 * @category Facades  
 * @package ExceptionHandler  
 * @author Hamed Ghasempour <[email protected]>  
 * @license MIT https://opensource.org/licenses/MIT  
 * @link null  
 */
 class Exception extends ExceptionFacade  
{  
    /**
     * This method will log an exception
     *
     * @param Throwable $throwable The throwable
     * @param string    $filePath  The file path that throwable should be log into
     *
     * @return void
     */
    public static function log(Throwable $throwable, string $filePath = null)
    {
        if (empty($filePath)) {
            $filePath = "/tmp/logs";
        }
        parent::log($throwable, $filePath);
    }
}