Get full tracebacks when warning is raised by setting

    warnings.showwarning = warn_with_traceback

    See also
    --------
    http://stackoverflow.com/questions/22373927/get-traceback-of-warnings
961861
def warn_with_traceback(message, category, filename, lineno, file=None, line=None):
    
    import traceback
    traceback.print_stack()
    log = file if hasattr(file, 'write') else sys.stderr
    settings.write(warnings.formatwarning(message, category, filename, lineno, line))
1181297
def format_exception(self):
        
        import traceback
        frames = self.get_traceback_frames()
        tb = [(f['filename'], f['lineno'], f['function'], f['context_line']) for f in frames]
        list = ['Traceback (most recent call last):\n']
        list += traceback.format_list(tb)
        list += traceback.format_exception_only(self.exc_type, self.exc_value)
        return list
1294773
def raise_with_traceback(exc, traceback=Ellipsis):
    
    if traceback == Ellipsis:
        _, _, traceback = sys.exc_info()
    raise exc.with_traceback(traceback)
254430
def get_traceback_stxt():
        
        #/
        exc_cls, exc_obj, tb_obj = sys.exc_info()
        
        #/
        txt_s = traceback.format_exception(exc_cls, exc_obj, tb_obj)
    
        #/
        res = ''.join(txt_s)
    
        return res
826525
def get_error_traceback(self):
        
        try:
            error_page = self.get_elm(class_name='error-page')
            traceback = error_page.get_elm(class_name='traceback')
        except NoSuchElementException:
            pass
        else:
            return traceback.text
1173957
def print_traceback(with_colors=True):
    
    #traceback.print_tb()
    import traceback
    stack = traceback.extract_stack()
    stack_lines = traceback.format_list(stack)
    tbtext = ''.join(stack_lines)
    if with_colors:
        try:
            from pygments import highlight
            from pygments.lexers import get_lexer_by_name
            from pygments.formatters import TerminalFormatter
            lexer = get_lexer_by_name('pytb', stripall=True)
            formatter = TerminalFormatter(bg='dark')
            formatted_text = highlight(tbtext, lexer, formatter)
            print(formatted_text)
        except Exception:
            print(tbtext)
    else:
        print(tbtext)
1090354
public function showFallbackWarning()
    {
        $request = $this->requestStack->getCurrentRequest();

        if ($request->query->has('act')) {
            return;
        }

        $messages = \System::importStatic('Messages');
        \Message::addRaw($messages->languageFallback());

        if ($this->hasInvalidTopLevels()) {
            \Message::addRaw('<p class="tl_error">'.$GLOBALS['TL_LANG']['ERR']['topLevelRegular'].'</p>');
        }
    }
971479
def dump_all_thread_tracebacks(exclude_thread_ids=None, file=None):
    
    if exclude_thread_ids is None:
        exclude_thread_ids = []
    if not file:
        file = sys.stdout
    import threading

    if hasattr(sys, "_current_frames"):
        print("", file=file)
        threads = {t.ident: t for t in threading.enumerate()}
        # noinspection PyProtectedMember
        for tid, stack in sys._current_frames().items():
            if tid in exclude_thread_ids:
                continue
            # This is a bug in earlier Python versions.
            # http://bugs.python.org/issue17094
            # Note that this leaves out all threads not created via the threading module.
            if tid not in threads:
                continue
            tags = []
            thread = threads.get(tid)
            if thread:
                assert isinstance(thread, threading.Thread)
                if thread is threading.currentThread():
                    tags += ["current"]
                # noinspection PyProtectedMember,PyUnresolvedReferences
                if isinstance(thread, threading._MainThread):
                    tags += ["main"]
                tags += [str(thread)]
            else:
                tags += ["unknown with id %i" % tid]
            print("Thread %s:" % ", ".join(tags), file=file)
            print_tb(stack, file=file)
            print("", file=file)
        print("That were all threads.", file=file)
    else:
        print("Does not have sys._current_frames, cannot get thread tracebacks.", file=file)
884492
def qr_code(self, instance):
        
        try:
            return self._qr_code(instance)
        except Exception as err:
            if settings.DEBUG:
                import traceback
                return "<pre>%s</pre>" % traceback.format_exc()
929781
def get_traceback(f):
  
  @functools.wraps(f)
  def wrapper(*args, **kwargs):
    try:
      return f(*args, **kwargs)
    except Exception, ex:
      ret = '#' * 60
      ret += "\nException caught:"
      ret += "\n" + '-' * 60
      ret += "\n" + traceback.format_exc()
      ret += "\n" + '-' * 60
      ret += "\n" + "#" * 60
      print sys.stderr, ret
      sys.stderr.flush()
      raise ex

  return wrapper
918344
def msg(cls, error=None, debug=True, trace=True):
        
        if debug and error is not None:
            print(error)
        # TODO: BUG: trace should only be printed if debug is true
        if trace:
            print(traceback.format_exc())
832331
def toggleTraceInfo( showTrace )
      if showTrace
         # this will print a very large amount of stuff
         set_trace_func proc { |event, file, line, id, binding, classname|  printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname }
         if block_given?
            yield
            set_trace_func nil
         end
      else
         set_trace_func nil
         if block_given?
            yield
            set_trace_func proc { |event, file, line, id, binding, classname|  printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname }
         end
      end
      self
   end
387607
def exception_format():
    
    return "".join(traceback.format_exception(
        sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
    ))
566210
def raise_and_log_error(self, error, message):
        
        self.log('raising %s, traceback %s\n' %
                 (error, traceback.format_exc()))
        raise error(message)
89336
def str_traceback(error, tb):
    
    if not isinstance(tb, types.TracebackType):
        return tb

    return ''.join(traceback.format_exception(error.__class__, error, tb))
862443
void showWarnings(SQLWarning warn) {
    if (warn == null) {
      return;
    }

    if (seenWarnings.get(warn) == null) {
      // don't re-display warnings we have already seen
      seenWarnings.put(warn, new java.util.Date());
      handleSQLException(warn);
    }

    SQLWarning next = warn.getNextWarning();
    if (next != warn) {
      showWarnings(next);
    }
  }
370264
def _error(self, exc_info):
        
        if self._exc_info:
            if self._traceback:
                return exc_info
            return exc_info[:2]
        return exc_info[1]