gpt4 book ai didi

c# - 如何获取有关异常的更多信息

转载 作者:太空狗 更新时间:2023-10-29 20:28:08 25 4
gpt4 key购买 nike

我在 64 位 Windows 7 上的 Visual Studio 2008 中创建了一个解决方案。

有效。

当我将它移到另一台机器上时,同样是 win 7、64 位,它崩溃了,几乎没有任何信息。

原来的问题是这样的:

call was rejected by callee

然后我实现了这个解决方案:

how to properly GetTypeFromProgID for visual studio 2008

但是,现在我的问题是,当我在另一台机器上运行可执行文件时,程序立即崩溃并显示以下信息:

Description:
Stopped working

Problem signature:
Problem Event Name: APPCRASH
Application Name: EmailSalesVolumeSolution.exe
Application Version: 1.0.0.0
Application Timestamp: 508064dd
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.17932
Fault Module Timestamp: 503285c2
Exception Code: e0434f4d
Exception Offset: 000000000000caed
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

我将代码包装在 try/catch 中,但仍然没有收到正确的错误消息:

static void Main()
{
try
{
EnvDTE80.DTE2 dte;
object obj = null;
System.Type t = null;

// Get the ProgID for DTE 8.0.
t = System.Type.GetTypeFromProgID("VisualStudio.DTE.9.0",
true);
// Create a new instance of the IDE.
obj = System.Activator.CreateInstance(t, true);
// Cast the instance to DTE2 and assign to variable dte.
dte = (EnvDTE80.DTE2)obj;

// Register the IOleMessageFilter to handle any threading
// errors.
MessageFilter.Register();
// Display the Visual Studio IDE.
dte.MainWindow.Activate();


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

// For example, get a reference to the solution2 object
// and do what you like with it.

// All done, so shut down the IDE...
dte.Quit();
// and turn off the IOleMessageFilter.
MessageFilter.Revoke();

}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

我如何确定异常发生的确切位置以及异常是什么?

我确实有一些非托管代码:

using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using System.Runtime.InteropServices;

namespace EmailSalesVolumeSolution
{
public class MessageFilter : IOleMessageFilter
{
//
// Class containing the IOleMessageFilter
// thread error-handling functions.

// Start the filter.
public static void Register()
{
IOleMessageFilter newFilter = new MessageFilter();
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(newFilter, out oldFilter);
}

// Done with the filter, close it.
public static void Revoke()
{
IOleMessageFilter oldFilter = null;
CoRegisterMessageFilter(null, out oldFilter);
}

//
// IOleMessageFilter functions.
// Handle incoming thread requests.
int IOleMessageFilter.HandleInComingCall(int dwCallType,
System.IntPtr hTaskCaller, int dwTickCount, System.IntPtr
lpInterfaceInfo)
{
//Return the flag SERVERCALL_ISHANDLED.
return 0;
}

// Thread call was rejected, so try again.
int IOleMessageFilter.RetryRejectedCall(System.IntPtr
hTaskCallee, int dwTickCount, int dwRejectType)
{
if (dwRejectType == 2)
// flag = SERVERCALL_RETRYLATER.
{
// Retry the thread call immediately if return >=0 &
// <100.
return 99;
}
// Too busy; cancel call.
return -1;
}

int IOleMessageFilter.MessagePending(System.IntPtr hTaskCallee,
int dwTickCount, int dwPendingType)
{
//Return the flag PENDINGMSG_WAITDEFPROCESS.
return 2;
}

// Implement the IOleMessageFilter interface.
[DllImport("Ole32.dll")]
private static extern int
CoRegisterMessageFilter(IOleMessageFilter newFilter, out
IOleMessageFilter oldFilter);
}
[ComImport(), Guid("00000016-0000-0000-C000-000000000046"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
interface IOleMessageFilter
{
[PreserveSig]
int HandleInComingCall(
int dwCallType,
IntPtr hTaskCaller,
int dwTickCount,
IntPtr lpInterfaceInfo);

[PreserveSig]
int RetryRejectedCall(
IntPtr hTaskCallee,
int dwTickCount,
int dwRejectType);

[PreserveSig]
int MessagePending(
IntPtr hTaskCallee,
int dwTickCount,
int dwPendingType);
}
}

在给我带来麻烦的机器上安装 VS 2008 Express 后,我现在得到这个:

enter image description here

最佳答案

您也可以尝试订阅 AppDomain.CurrentDomain.UnhandledException 事件:

AppDomain.CurrentDomain.UnhandledException += 
(sender, e) => MessageBox.Show(e.ExceptionObject.ToString());

Main 方法的顶部执行此操作。

关于c# - 如何获取有关异常的更多信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12963238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com