![](/img/trans.png)
[英]How to catch an unhandled exception in Windows Azure (Worker) Role
[英]how to catch an unhandled exception in windows phone 7 application?
如何捕获未处理的异常? 如果我的所有代码都包含在try catch
? 但是一个异常发生了,应用程序崩溃了...也许有一些一般的建议?
采用:
try
{
...my code
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(),"Error!",MessageBoxButton.OK);
}
示例代码不存在,因为有一个很大的代码,并做了很多事情......它看起来像某个地方出现错误,但它是try-catch没有显示的地方,应用程序只是关闭...
加:
var errorw = MessageBox.Show(e.ExceptionObject.ToString(), "error", MessageBoxButton.OK); e.Handled = true;
并且消息:参数不正确。
正如我们现在明白给出的参数在哪里和哪个不正确? 顺便说一句,当你返回应用程序的上一页时,忘记写下当你按Back时发生错误。
你会这样试试吗
// 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();
}
总有一本手册。
您是否尝试过Exception
的StackTrace
属性? 它显示了抛出异常的位置。
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace,"Error!",MessageBoxButton.OK);
}
确保在调试中构建应用程序,而不是在发布模式下。 然后,转到VS Debug-Exceptions菜单并检查所有'Thrown'列是否已启用。 之后,使用附加的调试器启动应用程序。 此外,您可以逐步执行代码。
嘿伙计们,你可以使用BugSense库来捕获数据,然后收集它! PS。 我是创始人之一
将您的代码放入Try-Catch Block。 我也遇到了这样的问题,但后来由异常处理方法处理。
try
{
// your code
}
catch (Exception ex)
{
throw (ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.