如何捕获 "AppName [procId] 中发生未处理的 win32 异常"?

20

使用C#、Visual Studio 2013和Windows Store App

稍微解释一下

创建一个简单的Windows Store App,用于处理存储的JSON数据。在数据量增加后,我开始收到消息Unhandled win32 exception occured in AppName [procId]. - 请参见以下图片:

输入图像描述

我尝试减少JSON文件中存储的数据量,但是在调试期间休息了一段时间后,我再次收到此消息。因此,情况是:如果我有很多数据,则可以在应用程序中执行几个操作(几个意味着5)并获得此异常,如果我具有最小数量的数据,则可以使用 应用程序稍微更多(大约12-17种不同操作)。 操作意味着-从文件读取,保存,加载页面等。

我稍微Google了一下,并发现了一些可能的原因:

  • 我必须在PC上设置DEP,按照以下步骤进行操作:
    1. 右键单击“我的电脑”。 然后选择“属性”。
    2. 选择“高级”选项卡。
    3. 选择“性能”的“设置”。
    4. 选择“数据执行保护”选项卡。
    5. 选择选项“仅为必要的Windows程序和服务打开DEP”。 如果已选择此选项,请单击“确定”,然后再次单击“确定”。
    6. 重新启动计算机。

尝试-无效

  • 检查并启用我的VISUAL STUDIO中的即时调试

输入图像描述

尝试-无效

  • 检查VS可以捕获哪种类型的异常-选择全部:

输入图像描述

尝试-无效

找到以下内容:

An unhandled win32 exception occurred in . Just-In-Time debugging this exception failed with the following error: The logged in user did not have access to debug the crashing application. This message indicates that Just-In-Time debugging failed because you do not have proper access permissions.

因此,意味着您没有适当的访问权限

尝试使用管理员权限启动我的应用程序:

输入图像描述

尝试-无效

  • 还阅读了许多来自这里的帖子。

发现这个这篇MSDN帖子很有用。尝试在我的应用程序中添加一些代码:

    public MainPage()
    {
        this.InitializeComponent();
        this.navigationHelper = new NavigationHelper(this);
        this.navigationHelper.LoadState += navigationHelper_LoadState;
        this.navigationHelper.SaveState += navigationHelper_SaveState;
        TimeBinding();
        Application.Current.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
    }

    static void MyHandler(object sender, UnhandledExceptionEventArgs args)
    {
        string e = args.Message.ToString();
    }

但是没有捕获到任何东西...

所以,尝试 - 没有帮助

问题:

  1. 我为什么会收到这个消息,除了我没有描述的可能原因外,还有什么其他可能导致类似于“在应用程序名[procId]中发生未处理的win32异常”的异常?
  2. 我是否正确理解了UnhandledException的使用?也许我对它的理解是错误的,所以我无法捕获所需的异常(我只是在学习.NET)?
1个回答

1

几个月前,我实际上为这项工作设计了一个错误控制系统。 在这个项目中,我使用了以下主要代码来捕获任何win32应用程序异常:

System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

// Catch all handled exceptions in managed code, before the runtime searches the Call Stack 
AppDomain.CurrentDomain.FirstChanceException += FirstChanceException;

// Catch all unhandled exceptions in all threads.
AppDomain.CurrentDomain.UnhandledException += UnhandledException;

// Catch all unobserved task exceptions.
TaskScheduler.UnobservedTaskException += UnobservedTaskException;

// Catch all unhandled exceptions.
System.Windows.Forms.Application.ThreadException += ThreadException;

// Catch all WPF unhandled exceptions.
Dispatcher.CurrentDispatcher.UnhandledException += DispatcherUnhandledException;

以及监听器方法:

/// <summary>
/// Used for handling WPF exceptions bound to the UI thread.
/// Handles the <see cref="System.Windows.Threading.DispatcherUnhandledExceptionEventHandler"/> events.
/// </summary>
[HandleProcessCorruptedStateExceptions]
private static DispatcherUnhandledExceptionEventHandler DispatcherUnhandledException
{
    // catch error ...            
}

/// <summary>
/// Used for handling WinForms exceptions bound to the UI thread.
/// Handles the <see cref="System.Threading.ThreadExceptionEventHandler"/> events in <see cref="System.Windows.Forms.Application"/> namespace.
/// </summary>
[HandleProcessCorruptedStateExceptions]
private static ThreadExceptionEventHandler ThreadException
{
    // catch error ...        
}

/// <summary>
/// Used for handling general exceptions bound to the main thread.
/// Handles the <see cref="AppDomain.UnhandledException"/> events in <see cref="System"/> namespace.
/// </summary>
[HandleProcessCorruptedStateExceptions]
private static UnhandledExceptionEventHandler UnhandledException
{
    // catch error ...        
}

/// <summary>
/// Used for handling System.Threading.Tasks bound to a background worker thread.
/// Handles the <see cref="UnobservedTaskException"/> event in <see cref="System.Threading.Tasks"/> namespace.
/// </summary>
[HandleProcessCorruptedStateExceptions]
private static EventHandler<UnobservedTaskExceptionEventArgs> UnobservedTaskException
{
    // catch error ...        
}

/// <summary>
/// This is new to .Net 4 and is extremely useful for ensuring that you ALWAYS log SOMETHING.
/// Whenever any kind of exception is fired in your application, a FirstChangeExcetpion is raised,
/// even if the exception was within a Try/Catch block and safely handled.
/// This is GREAT for logging every wart and boil, but can often result in too much spam, 
/// if your application has a lot of expected/handled exceptions.
/// </summary>
[HandleProcessCorruptedStateExceptions]
private static EventHandler<FirstChanceExceptionEventArgs> FirstChanceException
{
   // catch error ...        
}

如果您的代码中出现异常,您必须确保通过这些事件捕获异常,但是当应用程序在执行之前发生异常时,则不会引发这些事件以显示或执行任何操作。
例如,如果您没有完全添加所有引用程序集到您的项目中,则会在应用程序启动时引发异常。
另外,一些异常可能具有innerException,因为它们来自线程或任务。因此,您必须检查所有exception.innerException。
我希望能够为您解决问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接