X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=application%2Flfdb2%2Fexceptions.php;h=3f042647bdaf4f3e79b003769a5b614836277de1;hb=e5e15ddf7927dd5d518451a4fe535d6e4dfd19da;hp=e84a25e6248c3125845095b3ce5059622cdefaab;hpb=c085dd45543def1d9fdc641f3f38dc08faf6c505;p=lfdb2.git diff --git a/application/lfdb2/exceptions.php b/application/lfdb2/exceptions.php index e84a25e..3f04264 100644 --- a/application/lfdb2/exceptions.php +++ b/application/lfdb2/exceptions.php @@ -10,7 +10,7 @@ use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; * * @author Roland Haeder * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2022 LFDB2 Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Hub Developer Team * @license GNU GPL 3.0 or any newer version * * This program is free software: you can redistribute it and/or modify @@ -34,16 +34,22 @@ function lfdb2_exception_handler ($exceptionInstance) { // Init variable $backTrace = ''; + // Generate exception code + $exceptionCode = ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())); + // Get all call levels from backtrace foreach ($exceptionInstance->getTrace() as $idx => $traceArray) { // Init argument string $argsString = ''; - // Convert arguments type into human-readable - foreach ($traceArray['args'] as $arg) { - $argsString .= ', ' . gettype($arg); + // Arguments given? + if (isset($traceArray['args'])) { + // Convert arguments type into human-readable + foreach ($traceArray['args'] as $arg) { + $argsString .= ', ' . gettype($arg); + } + $argsString = substr($argsString, 2); } - $argsString = substr($argsString, 2); // Set missing file/line if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown'; @@ -81,7 +87,7 @@ Backtrace: --------------------------------------------------------------------------------\n", trim(html_entity_decode(strip_tags(get_class($exceptionInstance)))), trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))), - ($exceptionInstance instanceof FrameworkException ? $exceptionInstance->getHexCode() : '0x' . bin2hex($exceptionInstance->getCode())), + $exceptionCode, $exceptionInstance->getFile(), $exceptionInstance->getLine(), trim($backTrace) @@ -89,23 +95,28 @@ Backtrace: // Output the message print($message); + + // Exit with code + exit(hexdec($exceptionCode)); } elseif (is_object($exceptionInstance)) { // Output more details printf('exceptionInstance=%s', print_r($exceptionInstance, true)); + exit(255); } else { /* * Invalid exception instance detected! Do *only* throw exceptions that * extends our own exception 'FrameworkException' to get such nice * outputs like above. */ - printf('exceptionInstance[]=%s is invalid! Please inform the core developer team.' . PHP_EOL, gettype($exceptionInstance)); + printf('exceptionInstance[]=%s is invalid! Please inform the LFDB2 developer team.' . PHP_EOL, gettype($exceptionInstance)); + exit(255); } } // Error handler -function lfdb2_error_handler ($errno, $errstr, $errfile, $errline, array $errcontext) { +function lfdb2_error_handler (int $errno, string $errstr, string $errfile, int $errline, array $errcontext) { // Construct the message - $message = sprintf('File: %s, Line: %s, Code: %s, Message: %s', + $message = sprintf('File: %s, Line: %d, Code: %d, Message: %s', basename($errfile), $errline, $errno, @@ -117,9 +128,9 @@ function lfdb2_error_handler ($errno, $errstr, $errfile, $errline, array $errcon } // Assertion handler -function lfdb2_assert_handler (string $file, int $line, $code) { +function lfdb2_assert_handler (string $file, int $line, int $code) { // Empty code? - if ($code === '') { + if (empty($code)) { $code = 'Unknown'; } @@ -145,7 +156,7 @@ set_exception_handler('lfdb2_exception_handler'); // Init assert handling assert_options(ASSERT_ACTIVE , true); -assert_options(ASSERT_WARNING , false); +assert_options(ASSERT_WARNING , true); assert_options(ASSERT_BAIL , true); assert_options(ASSERT_QUIET_EVAL, false); assert_options(ASSERT_CALLBACK , 'lfdb2_assert_handler');