简体   繁体   English

如何在Windows Phone 7应用程序中捕获未处理的异常?

[英]how to catch an unhandled exception in windows phone 7 application?

how to catch an unhandled exception? 如何捕获未处理的异常? if all my code wrapped in a try catch ? 如果我的所有代码都包含在try catch but an exception occurs all the same, and the application crashes ... Maybe there is some general advice? 但是一个异常发生了,应用程序崩溃了...也许有一些一般的建议?

use: 采用:

        try
            {
             ...my code
            }
        catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(),"Error!",MessageBoxButton.OK);
            }

Sample code is not present, because there is a big code and done many things ... and it looks like somewhere an error occurs, but where it is try-catch does not show, and the application just closes ... 示例代码不存在,因为有一个很大的代码,并做了很多事情......它看起来像某个地方出现错误,但它是try-catch没有显示的地方,应用程序只是关闭...

add: 加:

var errorw = MessageBox.Show(e.ExceptionObject.ToString(), "error", MessageBoxButton.OK); e.Handled = true; 

And the message: The parameter is incorrect. 并且消息:参数不正确。

Just as we now understand where and what parameter has given is not true? 正如我们现在明白给出的参数在哪里和哪个不正确? By the way forgot to write that the error occurs when you press Back, when you return to the previous page of the application. 顺便说一句,当你返回应用程序的上一页时,忘记写下当你按Back时发生错误。

would you try like this 你会这样试试吗

      // Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender,ApplicationUnhandledExceptionEventArgs e)
{
    if (e.ExceptionObject is QuitException)
        return;

    if (System.Diagnostics.Debugger.IsAttached)
    {
        // An unhandled exception has occurred; break into the debugger
        System.Diagnostics.Debugger.Break();
    }

    //MessageBox.Show(e.ExceptionObject.ToString(), "Unexpected error", MessageBoxButton.OK);

    var errorWin = new ErrorWindow(e.ExceptionObject, "An unexpected error has occurred. Please click Send to report the error details.")
                       {Title = "Unexpected Error"};
    errorWin.Show();
    //((PhoneApplicationFrame) RootVisual).Source = new Uri("/Views/ErrorWindow.xaml", UriKind.Relative);

    e.Handled = true;
}

private class QuitException : Exception { }

public static void Quit()
{
    throw new QuitException();
}

There is always a manual. 总有一本手册。

UnhandledException event description. UnhandledException事件描述。

Have you tried the StackTrace property of Exception . 您是否尝试过ExceptionStackTrace属性? It shows you where the exception has been thrown. 它显示了抛出异常的位置。

catch (Exception ex)
{
    MessageBox.Show(ex.StackTrace,"Error!",MessageBoxButton.OK);
}

Make sure that you build application in debug, not release mode. 确保在调试中构建应用程序,而不是在发布模式下。 Than, go to VS Debug-Exceptions menu and check all 'Thrown' column to enabled. 然后,转到VS Debug-Exceptions菜单并检查所有'Thrown'列是否已启用。 After that, launch application with attached debugger. 之后,使用附加的调试器启动应用程序。 Also, you can execute your code step-by-step. 此外,您可以逐步执行代码。

Hey guys you could use the BugSense library to catch the data and then collect it! 嘿伙计们,你可以使用BugSense库来捕获数据,然后收集它! PS. PS。 I am one of the founders 我是创始人之一

Put your code in Try-Catch Block. 将您的代码放入Try-Catch Block。 I was also facing such problem, but then handled by Exception Handling Method. 我也遇到了这样的问题,但后来由异常处理方法处理。

try
 {

   // your code

 }

catch (Exception ex)
 {

   throw (ex);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Azure(工作器)角色中捕获未处理的异常 - How to catch an unhandled exception in Windows Azure (Worker) Role C#-Windows窗体-如何从任务中捕获未处理的异常 - C# - windows form - how to catch an unhandled exception from a task 如何将未处理的异常传递给线程中的应用程序捕获块 - How to pass unhandled exception to application catch block in thread Windows Service应用程序中未处理的异常 - unhandled exception in windows service application Windows Phone 8.1 UNHANDLED_EXCEPTION - Windows Phone 8.1 UNHANDLED_EXCEPTION 使用catch时Windows Service中未处理的异常(异常) - Unhandled exception in Windows Service when using catch(Exception) 如何捕获从延续中抛出的未处理异常? - How to catch an unhandled exception thrown from a continuation? C# Windows 表单应用程序未处理异常 - C# Windows Form Application Unhandled Exception Windows Mobile应用程序避免未处理的异常处理 - Windows Mobile Application avoiding Unhandled Exception Handling 应用程序崩溃而未调用未处理的异常方法Windows Phone 8 - App Crashing without calling Unhandled Exception method Windows Phone 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM