Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #6

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions webfiori/error/ErrorHandlerException.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
namespace webfiori\error;

use Exception;
use ErrorException;
/**
* This class is used to represent PHP errors which was converted to exceptions.
*
* @author Ibrahim
*/
class ErrorHandlerException extends Exception {
class ErrorHandlerException extends ErrorException {
private $debugTrace;
/**
* Creates new instance of the class.
Expand All @@ -18,8 +18,8 @@ class ErrorHandlerException extends Exception {
*
* @param string $file The path to the file at which the error happened.
*/
public function __construct(string $message = "", int $code = 0, string $file = '') {
parent::__construct($message, $code);
public function __construct(string $message = "", int $code = 0, string $file = '', int $line = 0) {
parent::__construct($message, $code, $code, $file, $line);
$this->debugTrace = [];
$trace = debug_backtrace();
$line = null;
Expand Down
9 changes: 4 additions & 5 deletions webfiori/error/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ class Handler {
private $exceptionsHandler;
private $shutdownFunction;
private function __construct() {
//ini_set('display_startup_errors', 1);
//ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
$this->errToExceptionHandler = function (int $errno, string $errString, string $errFile, int $errLine) {
//Convert errors to exceptions
$errClass = TraceEntry::extractClassName($errFile);
$errType = Handler::ERR_TYPES[$errno];
$message = 'An exception caused by an error. '.$errType['description'].': '.$errString.' at '.$errClass.' Line '.$errLine;
throw new ErrorHandlerException($message, $errno, $errFile);
throw new ErrorHandlerException($message, $errno, $errFile, $errLine);
};
$this->exceptionsHandler = function (Throwable $ex = null) {
Handler::get()->lastException = $ex;
Expand Down Expand Up @@ -141,9 +141,8 @@ private function __construct() {
}
};
$this->isErrOccured = false;
set_exception_handler($this->exceptionsHandler);
set_error_handler($this->errToExceptionHandler);

set_exception_handler($this->exceptionsHandler);
register_shutdown_function($this->shutdownFunction);
$this->handlersPool = [];
$this->handlersPool[] = new DefaultHandler();
Expand Down
Loading