Returns last exception as a string, or use in logging.
545989
def last_exception():
    
    exc_type, exc_value, exc_traceback = sys.exc_info()
    return "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
595868
protected function formatException(\Exception $exception)
    {
        if (!$this->pythonLike) {
            $s = (string) $exception;
            if (substr($s, -1) == "\n") {
                $s = substr($s, 0, -1);
            }
            return $s;
        }

        $s      = "Traceback (most recent call last):\n";
        $traces = array();
        foreach ($exception->getTrace() as $trace) {
            $origin = '';
            if (isset($trace['class'])) {
                $origin = $trace['class'].$trace['type'];
            }
            if (isset($trace['function'])) {
                $origin .= $trace['function'].'()';
            }
            if ($origin == '') {
                $origin = '???';
            }
            $file = isset($trace['file']) ? $trace['file'] : '{main}';
            $line = isset($trace['line']) ? $trace['line'] : 0;
            $traces[] = "File \"$file\", line $line, in $origin";
        }
        $s .= implode("\n", array_reverse($traces))."\n";
        $s .=   "Exception '" . get_class($exception) .
                "' with message '" . $exception->getMessage() .
                "' in " . $exception->getFile() .
                ":" . $exception->getLine();
        return $s;
    }
198107
def pformat(self, traceback=False):
        """"""
        buf = six.StringIO()
        if not self._exc_type_names:
            buf.write('Failure: %s' % (self._exception_str))
        else:
            buf.write('Failure: %s: %s' % (self._exc_type_names[0],
                                           self._exception_str))
        if traceback:
            if self._traceback_str is not None:
                traceback_str = self._traceback_str.rstrip()
            else:
                traceback_str = None
            if traceback_str:
                buf.write(os.linesep)
                buf.write(traceback_str)
            else:
                buf.write(os.linesep)
                buf.write('Traceback not available.')
        return buf.getvalue()
735981
function last(thing) {
		return thing.charAt ? thing.charAt(thing.length - 1) : thing[thing.length - 1];
	}
511534
def exception(self):
        """"""
        buf = traceback.format_exception_only(self.exc_type, self.exc_value)
        rv = "".join(buf).strip()
        return to_unicode(rv, "utf-8", "replace")
472371
private String getStackTrace(final Throwable exception) {

        if (exception != null) {

            StringBuilder sb = new StringBuilder();

            StackTraceElement[] stackTrace = exception.getStackTrace();
            for (StackTraceElement element : stackTrace) {
                sb.append(element.toString());
                sb.append('\n');
            }

            if (exception.getCause() != null) {

                StackTraceElement[] stackTraceCause = exception.getCause().getStackTrace();
                for (StackTraceElement element : stackTraceCause) {
                    sb.append(element.toString());
                    sb.append('\n');
                }

            }

            return sb.toString();
        }

        return null;
    }
723923
public static String getTotalStackTrace( final Throwable    exception )
    {
        if( isBroadestFirst() )
        {
            StringWriter    writer = new StringWriter();
            exception.printStackTrace( new PrintWriter( writer, true ) );

            return writer.toString();
        }

        //
        //     Reverse the order of the exceptions
        //
        List<Throwable>    exceps = new ArrayList<Throwable>();
        Throwable    rev = exception;

        while ( rev != null && rev.getCause() != rev )
        {
            exceps.add( 0, rev );

            rev = rev.getCause();
        }

        StringBuffer   buffer = new StringBuffer();

        for ( int ii = 0; ii < exceps.size(); ii++ )
        {
            Throwable    ex = exceps.get( ii );
            Throwable    parent = null;
            if ( ii != 0 )
            {
                buffer.append( "\n\nIn context of:\n" );
                parent = exceps.get( ii -1 );
            }

            buffer.append( ex.toString() );
            StackTraceElement[]    trace = ex.getStackTrace();
            for ( int jj=0; jj < trace.length; jj++)
            {
                StackTraceElement    traceElement = trace[jj];

                boolean    done = false;
                if ( parent != null )
                {
                    StackTraceElement[]    parentTrace = parent.getStackTrace();
                    for ( int kk=0; kk < parentTrace.length; kk++ )
                    {
                        if ( parentTrace[kk].equals( traceElement ) )
                        {
                            done = true;
                            break;
                        }
                    }
                }

                buffer.append("\n\tat " + traceElement );

                if ( done )
                {
                    buffer.append( "\n\t..." );
                    break;
                }
            }
        }

        return buffer.toString();
    }
409408
private String getStackTrace(AbstractRestException data) {
        StringBuilderWriter writer = new StringBuilderWriter();
        try {
            data.printStackTrace(new PrintWriter(writer));
            return writer.getBuilder().toString();
        } finally {
            writer.close();
        }
    }
900811
public static String getExceptionMessage(Throwable exception)
    {
        StringWriter        out = new StringWriter();
        exception.printStackTrace(new PrintWriter(out));
        BufferedReader      in = new BufferedReader(new StringReader(out.toString()));
        try
        {
            StringBuilder       str = new StringBuilder();
            for(;;)
            {
                String  line = in.readLine();
                if ( line == null )
                {
                    break;
                }
                if ( str.length() > 0 )
                {
                    str.append(", ");
                }
                str.append(line);
            }
            return str.toString();
        }
        catch ( IOException e )
        {
            // ignore
        }
        return "n/a";
    }
1026161
public static String getTrimmedStackTrace(Throwable exception) {
        List<String> trimmedStackTraceLines = getTrimmedStackTraceLines(exception);
        if (trimmedStackTraceLines.isEmpty()) {
            return getFullStackTrace(exception);
        }

        StringBuilder result = new StringBuilder(exception.toString());
        appendStackTraceLines(trimmedStackTraceLines, result);
        appendStackTraceLines(getCauseStackTraceLines(exception), result);
        return result.toString();
    }
100270
def exceptionToString(e):
    """"""
    exc_type, exc_obj, exc_tb = sys.exc_info()
    s="EXCEPTION THROWN UNEXPECTEDLY"
    s+="  FILE: %s\n"%os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    s+="  LINE: %s\n"%exc_tb.tb_lineno
    s+="  TYPE: %s\n"%exc_type
    return s
1291711
public static String exceptionToString(Exception e)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        return sw.toString();
    }
1193228
public static String getStackTraceString(Throwable throwable) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            pw.println(throwable.toString());
            throwable.printStackTrace(pw);
            pw.flush();
            return sw.toString();
        } finally {
            closeQuietly(pw);
            closeQuietly(sw);
        }
    }
712544
public String getExceptionStackTrace() {
        Throwable t = getException();
        if (t == null) {
            return null;
        }
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        t.printStackTrace(pw);
        return sw.toString();
    }
589063
@Override
   public long getLastModified()
   {
      try
      {
         if (!connected)
         {
            connect();
         }

         return nodeRepresentation.getLastModified();
      }
      catch (IOException e)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }
      catch (RepositoryException e)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }
      return 0;
   }
321314
public function getLastError(): string
    {
        if ($this->isConnected() && $this->socket) {
            $err = @socket_last_error($this->socket);
            if ($err) {
                $err = socket_strerror($err);
            }
            if (!$err) {
                $err = 'Unknown error';
            }
            return $err;
        } else {
            return 'Not connected';
        }
    }
740660
def log_exception(exc_info=None, stream=None):
    """"""
    exc_info = exc_info or sys.exc_info()
    stream = stream or sys.stderr
    try:
        from traceback import print_exception
        print_exception(exc_info[0], exc_info[1], exc_info[2], None, stream)
        stream.flush()
    finally:
        exc_info = None