Track the exception error.

@param  \Exception  $exception

@return int
431174
public function track(Exception $exception)
    {
        return $this->getModel()->newQuery()->firstOrCreate([
            'code'    => $this->getCode($exception),
            'message' => $exception->getMessage(),
        ])->getKey();
    }
1168309
public function exception($exception)
    {
        try {
            foreach ($this->handlers as $handler) {
                $handler($exception);
            }
        } catch (\Throwable $e) {
            $msg = "Infinity loop in exception & error handler. \nMessage:\n" . $e;

            if ($this->app->get('system.debug')) {
                exit($msg);
            }

            exit($e->getMessage());
        }

        exit();
    }
36542
protected function error(Request $request, \Exception $exception) {
        return $request->getTarget() . ' threw '
        . get_class($exception) . ': '
        . $exception->getMessage() . "\n"
        . $exception->getTraceAsString();
    }
1361344
public function getException($exception)
    {
        return array(
          'type' => 'exception',
          'tid' => $this->tid,
          'action' => $this->action,
          'method' => $this->method,
          'message' => $exception->getMessage(),
          'where' => $exception->getTraceAsString()
        );
    }
732832
public static function handleException($exception)
    {
        static::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception, true);
    }
396122
public function return404($notifier = false, \Exception $exception = null)
    {
    	if (!defined('ERROR_404'))
    	{
    	    define('ERROR_404', 'Y');
    	}

        \CHTTP::SetStatus('404 Not Found');

        if ($exception !== false)
        {
            if ($notifier === false)
            {
                $this->exceptionNotifier = false;
            }

            if ($exception instanceof \Exception)
            {
                throw $exception;
            }
            else
            {
                throw new \Exception('Page not found');
            }
        }
    }
728762
public static function exceptionHandler($exception)
    {
        if (DEBUG) {
            self::outputErrorHtml($exception->getMessage(), @$exception->timestamp, $exception->getFile(), $exception->getLine(), $exception);
        }
        elseif ($exception instanceof ConfigurationException) {
            self::outputErrorHtml("Configuration error", @$exception->timestamp, false, false, "Please contact administrator.");
        }
        
        error_log($exception);
    }
612412
public function logException(\Exception $exception)
    {
        $this->logError('Error: ' . get_class($exception) . ' - ' . $exception->getMessage() . ' (Code: ' . $exception->getCode() . ')');
        $this->logError('File: ' . $exception->getFile() . ' / Line: ' . $exception->getLine());
    }
321413
protected function getExceptionStatusCode(Exception $exception, $defaultStatusCode = null): int
    {
        if (null === $defaultStatusCode) {
            $defaultStatusCode = 500;
        }

        return ($exception instanceof HttpExceptionInterface) ? $exception->getStatusCode() : $defaultStatusCode;
    }
221129
protected function getBacktrace(\Exception $exception)
    {
        $backtrace = array();

        $backtrace[] = '---';
        $backtrace[] = $this->getErrorMessage($exception);
        $backtrace[] = '---';

        // Allow marshalling of the trace: PHP marks getTraceAsString as final :-(
        if (method_exists($exception, 'getPreviousTraceAsString')) {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getPreviousTraceAsString()));
        } else {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getTraceAsString()));
        }

        if (($previous = $exception->getPrevious())) {
            $backtrace = array_merge($backtrace, $this->getBacktrace($previous)); // Recurse
        }

        return $backtrace;
    }
372206
protected function _method(Exception $exception)
    {
        $exception = $this->_unwrap($exception);
        list(, $baseClass) = namespaceSplit(get_class($exception));

        if (substr($baseClass, -9) === 'Exception') {
            $baseClass = substr($baseClass, 0, -9);
        }

        $method = Inflector::variable($baseClass) ?: 'error500';

        return $this->method = $method;
    }
183013
private function logException(Exception $exception): void
    {
        if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) {
            return;
        }

        $this->logger->critical(
            sprintf(
                'Uncaught PHP Exception %s: "%s" at %s line %s',
                get_class($exception),
                $exception->getMessage(),
                $exception->getFile(),
                $exception->getLine()
            ),
            ['exception' => $exception]
        );
    }
172355
protected function getStatusCode(Exception $exception)
    {
        if ($exception instanceof ValidationException) {
            return $exception->status;
        }

        return $this->getExceptionStatusCode($exception);
    }
668973
public function Exception ($exception)
	{

		// Auditlog
		
		$auditlog	= Sonic::getResource ('auditlog');

		if ($auditlog instanceof Resource\Audit\Log)
		{
			$auditlog::_Log (get_called_class () . '\\' . $this->action, 7, $this->request, array (
				'file'		=> $exception->getFile (),
				'line'		=> $exception->getLine (),
				'message'	=> $exception->getMessage ()
			));
		}
		
		// Display message
		
		echo 'Uncaught exception `' . $exception->getMessage () . '` in ' . $exception->getFile () . ' on line ' . $exception->getLine ();
		
	}
128762
public function errorhandler($exception) {
		$errstr		= $exception->getMessage();
		$errcode	= $exception->getCode();
		$backtrace	= $exception->getTrace();
		
		// the same should not be outputted more than once
		if ($errstr == $this->lasterror) return;
		$this->lasterror = $errstr;

		// count errors to produce unique ids
		$this->errorcounter++;

		// if it is an error throw away the first backtrace item
		if ($exception instanceof ErrorException) array_shift($backtrace);
		
		// add actual error to backtrace
		$bt['file'] = $exception->getFile();
		$bt['line'] = $exception->getLine();
		array_unshift($backtrace, $bt);
		
		// clean array
		$backtrace_keys = ['file'=>'', 'line'=>'', 'class'=>'', 'object'=>'', 'type'=>'', 'function'=>'', 'args'=>[]];
		foreach ($backtrace as $key => $value) {
			$backtrace[$key] = array_merge($backtrace_keys, $value);
		}
		
		// set the error code string
		if ($exception instanceof ErrorException) $errordescription = $this->errortypes[ $exception->getSeverity() ];
		elseif ($errcode == 0) $errordescription = 'EXCEPTION';
		else $errordescription = 'EXCEPTION (Code '.$errcode.')';

		// show error on screen
		if (!is_int($this->config['output']['screen'])) {
			die(__CLASS__ . ': debug.output.screen has to a valid PHP timestamp.');
		}

		if (time() < $this->config['output']['screen']) {
			$error = $this->_errorhandler_output($errstr, $backtrace, $errordescription);
			echo $error;
		}

		// log error in logfile
		if (!is_int($this->config['output']['file'])) {
			die(__CLASS__ . ': debug.output.file has to a valid PHP timestamp.');
		}

		if (time() < $this->config['output']['file']) {
			$this->_errorhandler_file($errstr, $backtrace, $errordescription);
		}

		// trigger event/hook
		if ($this->_event_object !== null) {
			$this->_event_object->trigger('core.after_exception', $exception);
		}
	}
416964
protected function _logException(Exception $exception) {
		if ($this->is404($exception)) {
			$level = LOG_ERR;
			Log::write($level, $this->_getMessage($exception), ['404']);
			return false;
		}
		return parent::_logException($exception);
	}
1207570
protected function handleException(\Exception $exception)
    {
        $this->response->setStatus(500);
        // may be we want also an exceptionHandler e.g. to notify somebody, ...
        $this->addFlashMessage(
            $exception->getMessage(),
            get_class($exception),
            Message::SEVERITY_ERROR,
            [],
            $exception->getCode()
        );
    }