Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

c# - Globally catch exceptions before returning control to COM client?

My C# code is being run through COM from unmanaged code (which happens to be VB6). Mainly for debugging & logging purposes I would like to catch any C# exceptions before they make their way back to the unmanaged code.

In comparison, for other "subsystems" like Winforms and WPF it is possible to do something like this - both of those offer an event that you can use to handle exceptions as you see fit. I guess in those instances your application code is being executed from those subsystems as a starting point, so that provides the 'hook' where the exceptions can be caught and corresponding events raised.

I'm looking for something similar (if it exists) from the COM interop "subsystem".

This answer mentions:

The CLR installs a catch-all exception handler in its interop layer

Does the mentioned "interop layer" makes accessible any event like this? Or some other mechanism to act on an exception before it heads to the unmanaged code?

Note - I don't see anything for COM mentioned in this very well regarded answer, so maybe that indicates this is not possible.

question from:https://stackoverflow.com/questions/65849088/globally-catch-exceptions-before-returning-control-to-com-client

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...