public function throwException($message, $node = null, $code = 0, $previous = null)
    {
        $pattern = "Failed to compile: %s \nLine: %s \nOffset: %s";

        $location = $node ? $node->getSourceLocation() : null;

        $path = $location ? $location->getPath() : $this->getPath();
        $line = $location ? $location->getLine() : 0;
        $offset = $location ? $location->getOffset() : 0;
        $offsetLength = $location ? $location->getOffsetLength() : 0;

        if ($path) {
            $pattern .= "\nPath: $path";
        }

        throw new CompilerException(
            new SourceLocation($path, $line, $offset, $offsetLength),
            vsprintf($pattern, [
                $message,
                $line,
                $offset,
            ]),
            $code,
            $previous
        );
    }