catch another process unhandled exception
You can try something like that to avoid the debugger question to appear, you won't get the exception but only the exit code:
class Program
{
static void Main(string[] args)
{
try
{
ProcessStartInfo info =
new ProcessStartInfo("ErroneusApp.exe");
info.ErrorDialog = false;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
info.UseShellExecute = false;
System.Diagnostics.Process p =
System.Diagnostics.Process.Start(info);
p.EnableRaisingEvents = true;
p.Exited += p_Exited;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
static void p_Exited(object sender, EventArgs e)
{
Process p = sender as Process;
if (p != null)
{
Console.WriteLine("Exited with code:{0} ", p.ExitCode);
}
else
Console.WriteLine("exited");
}
}
In this question they provided another workaround for that, but changing some registry values.
If you are calling to a .Net executable assembly you can load it and (at your own risk :D ) call to the Main method of the Program class into a try_catch statement:
Assembly assembly = Assembly.LoadFrom("ErroneusApp.exe");
Type[] types= assembly.GetTypes();
foreach (Type t in types)
{
MethodInfo method = t.GetMethod("Main",
BindingFlags.Static | BindingFlags.NonPublic);
if (method != null)
{
try
{
method.Invoke(null, null);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
break;
}
}
But be aware of the security risks you are introducing doing that.