如何捕获“AppName [procId]中发生未处理的win32异常。”

时间:2014-03-16 21:49:59

标签: c# .net exception-handling windows-store-apps visual-studio-2013

使用c#,Visual Studio 2013,Windows应用商店

有点长的解释

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

enter image description here

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

搜索一点点,发现几个可能的原因:

  • 我必须在PC上设置DEP,然后执行以下步骤:

    1. 右键单击“我的电脑”。然后选择“属性”。
    2. 选择“高级”标签。
    3. 为“效果”选择“设置”。
    4. 选择“数据执行保护”选项卡。
    5. 选择选项“仅为基本Windows程序和服务启用DEP。”如果已选择此选项,请单击“确定”,然后再次单击“确定”。
    6. 重新启动计算机。

尝试 - 没有帮助

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

enter image description here

尝试 - 没有帮助

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

enter image description here

尝试 - 没有帮助

发现下一个:

  

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

因此,表示您没有适当的访问权限

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

enter image description here

尝试 - 没有帮助

  • 还阅读了here的大量帖子。

找到this,因此this 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. 为什么我收到此消息以及我未描述的可能原因可能是"Unhandled win32 exception occured in AppName [procId]."等异常的根本原因?
  2. 我是否正确理解UnhandledException的用法?也许我错了,所以我无法捕获所需的异常(我只是在研究.NET)?

1 个答案:

答案 0 :(得分:1)

几个月前,我为这项工作设计了一个Error Control System。 在这个项目中,我使用这个主要代码来捕获任何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 ,因为它来自threadtask。因此,您必须全部检查exception.innerException

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

相关问题