Beispiel #1
0
void OpenHome::UnhandledExceptionHandler(Exception& aException)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s at %s:%lu in thread %s\n", aException.Message(), aException.File(), (unsigned long)aException.Line(), thName.Ptr());

    TInt len = 8*1024;
    char* msg = new char[len];
    if (msg != NULL) {
        (void)strncpy(msg, buf, len);
        len -= (TInt)strlen(buf);
        (void)strncat(msg, "\n", len);
        len -= 2;

        THandle stackTrace = aException.StackTrace();
        TUint count = Os::StackTraceNumEntries(stackTrace);
        for (TUint i=0; i<count; i++) {
            const char* entry = Os::StackTraceEntry(stackTrace, i);
            (void)strncat(msg, entry, len);
            len -= (TInt)strlen(entry) + 2;
            if (len < 0) {
                break;
            }
            (void)strncat(msg, "\n", len);
        }
    }
    if (len > 0) {
        (void)strncat(msg, "\n", len);
    }

    CallFatalErrorHandler((msg!=NULL? msg : buf));
    delete msg;
}
Beispiel #2
0
//-----------------------------------------------------------------------------------------------------------------------------------------------------
VOID Application::OnException(Exception& E)
{
  Trace0Enter("");

  StringBuilder Message;

  Message.AppendLine(TEXT("UNHANDLED EXCEPTION"));
  Message.AppendFormatLine(TEXT("Exception Type: %s::%s"), E.GetType()->Namespace(), E.GetType()->Name() );
  Message.AppendFormatLine(TEXT("Description: %s"), E.Description().ConstStr() );

  Message.AppendLine(TEXT("\nStack Trace:"));
  
  for( SIZE_T i=0; i<E.StackTrace().Length(); i++ )
  {
#if defined(UNICODE)
    if (E.StackTrace()[i].Symbol().SourceFile() != 0)
      Message.AppendFormatLine(TEXT("0x%p %S() at %S:%d"), E.StackTrace()[i].InstructionPtr(), E.StackTrace()[i].Symbol().Name(), E.StackTrace()[i].Symbol().SourceFile(), E.StackTrace()[i].Symbol().SourceLine() );
    else
      Message.AppendFormatLine(TEXT("0x%p %S()"), E.StackTrace()[i].InstructionPtr(), E.StackTrace()[i].Symbol().Name() );
#else
    if (E.StackTrace()[i].Symbol().SourceFile() != 0)
      Message.AppendFormatLine(TEXT("0x%p %s()\r\n  at %s:%d"), E.StackTrace()[i].InstructionPtr(), E.StackTrace()[i].Symbol().Name(), Path::Filename(E.StackTrace()[i].Symbol().SourceFile()).ConstStr(), E.StackTrace()[i].Symbol().SourceLine() );
    else
      Message.AppendFormatLine(TEXT("0x%p %s()"), E.StackTrace()[i].InstructionPtr(), E.StackTrace()[i].Symbol().Name() );
#endif
  }

	Trace(TraceLevel::ERROR, this, Message.ToString() );

	Debug::GenerateCoreDump();
}