Thank you all for your helpful suggestions. But I found my own answer that looks good.
Dotnet 4 has
ExceptionServices[
^] and the AppDomain that allows one to add
FirstChanceException[
^] handler to an AppDomain. So we simply add this handler. And we can make a wrapper around the third party clr executable by loading it into the appdomain. So we can trace exceptions already caught. And this is enough we don't want to handle them only to intercept. And it is working also with "client" applications that need earlier .net.
I have only a proof of concept, but it seems to work!
The application with the exception:
using System;
namespace _throw
{
class Program
{
public static void Main(string[] args)
{
try
{
throw new NotImplementedException("catch this");
}
catch
{
}
}
}
}
And the handler:
using System;
using System.Runtime.ExceptionServices;
namespace catchh
{
class Program
{
public static void Main()
{
AppDomain.CurrentDomain.FirstChanceException += FirstChance;
AppDomain.CurrentDomain.ExecuteAssembly("throw.exe");
Console.ReadKey();
}
static void FirstChance(object sender, FirstChanceExceptionEventArgs e)
{
Console.WriteLine("Exception: {0}\nMessage: {1}\nStack trace:\n{2}", e.Exception.GetType().FullName, e.Exception.Message, e.Exception.StackTrace);
}
}
}
The article with more details can be found here:
http://firstchanceexception.com/tag/appdomain/[
^].