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

gbk*_*gbk 18 .net c# exception-handling windows-store-apps visual-studio-2013

使用c#,Visual Studio 2013,Windows Store App

一点点解释

创建一些适用于JSON存储数据的简单Windows应用商店应用.在增加数据量后,我开始收到消息Unhandled win32 exception occured in AppName [procId].- 请参见下图:

在此输入图像描述

我尝试减少JSON文件中存储的数据量,但在调试过程中休息一段时间后,我再次收到此消息.所以情况 - 如果我有很多数据 - 我可以在应用程序中进行一些操作(很少意味着5)并得到这个例外,如果我有最少量的数据我可以使用app多一点(意味着12-17个不同操作).操作方式 - 从文件读取,保存,加载页面等.

google了一下,发现了几个可能的原因:

  • 我必须在PC上设置DEP,然后按照以下步骤操作:

    1. 右键单击"我的电脑".然后选择"属性".
    2. 选择"高级"选项卡.
    3. 选择"性能"的"设置".
    4. 选择"数据执行保护"选项卡.
    5. 选择"仅为基本Windows程序和服务打开DEP"选项.如果已选择此选项,请单击"确定",然后再次单击"确定".
    6. 重启你的电脑.

尝试 - 没有帮助

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

在此输入图像描述

尝试 - 没有帮助

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

在此输入图像描述

尝试 - 没有帮助

找到下一个:

发生了未处理的win32异常.Just-In-Time调试此异常失败,并出现以下错误:登录用户无权调试崩溃的应用程序.此消息表明Just-In-Time调试失败,因为您没有适当的访问权限.

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

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

在此输入图像描述

尝试 - 没有帮助

  • 还从这里阅读了很多帖子.

发现这个,所以这个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();
    }
Run Code Online (Sandbox Code Playgroud)

但没有抓住......

所以,尝试 - 没有帮助

问题:

  1. 为什么我收到此消息以及我未描述的可能原因可能是异常的根本原因"Unhandled win32 exception occured in AppName [procId]."
  2. 我是否理解使用方法UnhandledException?也许我错了,所以我无法捕获所需的异常(我只是在研究.NET)?

Beh*_*zad 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;
Run Code Online (Sandbox Code Playgroud)

和侦听器方法:

/// <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 ...        
}
Run Code Online (Sandbox Code Playgroud)

如果在代码中引发异常,则必须确保通过此事件捕获该异常,但是当在执行应用程序之前发生异常时,不会引发此事件来显示或执行任何操作。
例如,您没有完全将所有引用程序集添加到您的项目中,然后这会导致在应用程序启动时抛出异常。

另外一些异常可能有innerException,因为是从athreadtasks 引发的。所以你必须全部检查一下exception.innerException

我希望能为您的问题提供解决方案。