Returns a filtered backtrace using regular expressions
@param  mixed      $exception
@return array|void
352880
public function getBacktrace($exception = null)
    {
        $backtrace = parent::getBacktrace($exception);

        foreach ($backtrace as $index => $backtraceCall) {
            $functionName = $this->buildFunctionName($backtraceCall);
            foreach ($this->filteredFunctions as $pattern) {
                if (preg_match('/'.$pattern.'/', $functionName)) {
                    unset($backtrace[$index]);
                    break;
                }
            }
        }

        return array_values($backtrace);
    }
366146
public static function normalizeBacktrace(array $trace)
    {
        $trace = new Data($trace);

        $args = [];

        foreach ($trace['args'] as $arg) {
            if (is_array($arg)) {
                $arg = 'Array';
            } elseif (is_object($arg)) {
                $arg = ReflectionHelper::getShortName($arg);
            } elseif (is_string($arg)) {
                if (Mbstring::strlen($arg) > 20) {
                    $arg = Utf8String::substr($arg, 0, 20) . '...';
                }

                $arg = Str::wrap($arg);
            } elseif ($arg === null) {
                $arg = 'NULL';
            } elseif (is_bool($arg)) {
                $arg = $arg ? 'TRUE' : 'FALSE';
            }

            $args[] = $arg;
        }

        return [
            'file' => !empty($trace['file']) ? static::replaceRoot($trace['file']) . ' (' . $trace['line'] . ')' : null,
            'function' => ($trace['class'] ? $trace['class'] . $trace['type'] : null) . $trace['function'] .
                sprintf('(%s)', implode(', ', $args)),
            'pathname' => $trace['file'],
            'line' => $trace['line']
        ];
    }
1091648
protected function matchesCondition($return, $exception = null)
    {
        $matched  = false;
        foreach($this->conditions as $expression) {
            if ("isExceptionOf" === $expression["compare"]) {
                $matched = Comparator::isInstanceOf($exception, $expression["value"]);
            } else {
                $matched = Comparator::$expression["compare"]($return, $expression["value"]);
            }
            if ($matched) {
                $matched = $expression["action"];
                break;
            }
        }
        
        return $matched;
    }
1071082
private function serializeException(\Exception $exception)
    {
        $result = [
            'code'    => $exception->getCode(),
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
            'trace'   => $exception->getTraceAsString(),
        ];

        if ($exception->getPrevious() !== null) {
            $result['previous'] = $this->serializeException($exception->getPrevious());
        }

        return $result;
    }
1318577
private function formatExceptionStacktrace($exception)
    {
        if (!$exception instanceof Throwable) {
            return '';
        }

        $trace = $this->formatStacktraceEntry('ERR', [
            'function' => $exception->getMessage(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
        ]);

        if (!$this->logStacktraces) {
            return $trace;
        }

        foreach ($exception->getTrace() as $index => $entry) {
            $trace .= $this->formatStacktraceEntry(sprintf('#%d', $index), $entry);
        }

        return $trace;
    }
49807
public function backtraceFocus($pattern = null)
    {
        if ($pattern === null) {
            return $this->_backtraceFocus;
        }
        $patterns = is_array($pattern) ? $pattern : [$pattern];
        foreach ($patterns as $key => $value) {
            $patterns[$key] = preg_quote($value, '~');
        }
        $pattern = join('|', $patterns);
        return $this->_backtraceFocus = strtr($pattern, ['\*' => '.*', '\?' => '.']);
    }
412062
public function trackException(Exception $exception)
    {
        try {
            $this->manager->trackException($exception);
        }
        catch (Exception $e) {
            // Ignore Tracker exceptions
        }

        // Call Laravel Exception Handler
        return call_user_func($this->originalExceptionHandler, $exception);
    }
850982
private function formatException(\Exception $exception)
    {
        $result = [
            'message' => $exception->getMessage(),
            'type'      => get_class($exception),
            'code'      => $exception->getCode(),
            'trace' => [
                [
                    'file' => $exception->getFile() ?: 'unknown',
                    'line' => $exception->getLine() ?: 'unknown',
                ]
            ]
        ];

        foreach ($exception->getTrace() as $frame) {
            $result['trace'][] = $this->formatStackFrame($frame);
        }

        if ($previous = $exception->getPrevious()) {
            $result['previous'] = $this->formatException($previous);
        }

        return $result;
    }
910480
public function only($exceptions)
    {
        $data = [];

        if (! is_array($exceptions)) {
            $exceptions = func_get_args();
        }

        foreach ($exceptions as $exception) {
            if (isset($this->input[$exception])) {
                $data[$exception] = $this->input[$exception];
            }
        }

        return $data;
    }
1224558
public function catches($exception) {
    $exceptions = func_get_args();

    foreach ($this->getCatches() as $catch) {
      if (in_array($catch->getExceptionType()->getAbsolutePath(), $exceptions, TRUE)) {
        return TRUE;
      }
    }
    return FALSE;
  }
578262
private function processException(Exception $exception)
    {
        $context = [
            'exception_class' => get_class($exception),
        ];

        return $this->addStackContext($exception, $context);
    }
1314805
public function processException($exception)
    {
        $requestDetails = [
            'type' => 'exception',
            'data' => json_encode([
                'exception_content' => $exception->getMessage() ?? 'No message',
                'exception_trace' => $exception->getTrace(),
                'exception_file' => $exception->getFile(),
                'exception_line' => $exception->getLine(),
            ]),
        ];

        return array_merge($this->baseRequest(), $requestDetails);
    }
1077015
protected function shouldntBacktrace(Exception $e)
    {
        foreach ($this->dontBacktrace as $type) {
            if ($e instanceof $type) {
                return true;
            }
        }
        
        return false;
    }
409866
static public function backtrace($deep=0)
    {
        $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, $deep + 1);
        if (isset($bt[$deep])) {
            return $bt[$deep];
        }

        return array();
    }
945897
public static function backtrace($trace = null)
	{
		$trace or $trace = debug_backtrace();

		if (\Fuel::$is_cli) {
			// Special case for CLI since the var_dump of a backtrace is of little use.
			$str = '';
			foreach ($trace as $i => $frame)
			{
				$line = "#$i\t";

				if ( ! isset($frame['file']))
				{
					$line .= "[internal function]";
				}
				else
				{
					$line .= $frame['file'] . ":" . $frame['line'];
				}

				$line .= "\t";

				if (isset($frame['function']))
				{
					if (isset($frame['class']))
					{
						$line .= $frame['class'] . '::';
					}

					$line .= $frame['function'] . "()";
				}

				$str .= $line . "\n";

			}

			return $str;
		}
		else
		{
			return static::dump($trace);
		}
	}
260710
public static function exceptionToArray($exception, $includePrevious = false)
    {
        $array = [
            'message' => $exception->getMessage(),
            'code' => $exception->getCode(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'trace' => $exception->getTraceAsString(),
        ];

        if ($includePrevious) {
            $array['previous'] = self::exceptionToArray($exception->getPrevious(), true);
        }

        return $array;
    }
705538
protected function prepareReplacements(Exception $exception): array
    {
        $statusCode = $this->getStatusCode($exception);

        if (!$message = $exception->getMessage()) {
            $message = sprintf('%d %s', $statusCode, Response::$statusTexts[$statusCode]);
        }

        $replacements['message'] = $message;

        if ($code = $exception->getCode()) {
            $replacements['code'] = $code;
        }

        $replacements['status_code'] = $statusCode;


        if ($exception instanceof ApiException && $exception->apiMessage->getErrors()) {
            $replacements['errors'] = $exception->apiMessage->getErrors();
        }


        if ($exception instanceof ApiException && null !== $exception->apiMessage->getHypermedia()) {
            $replacements += $exception->apiMessage->getHypermedia();
        }



        if ($this->runningInDebugMode()) {
            $replacements['debug'] = [
                'line'  => $exception->getLine(),
                'file'  => $exception->getFile(),
                'code'  => $exception->getCode(),
                'class' => \get_class($exception),
                'trace' => explode("\n", $exception->getTraceAsString()),
            ];
        }

        return array_merge($replacements, $this->replacements);
    }