0

I have some windows applications. I will run all those Apps one by one from a console application. If any application produces run time exception, then it should save that exception's details and need to move to the next application.

I have tried the solution given in the below link: catch another process unhandled exception. But it is not solving my problem.

For Ex: From my console app, calling the windows app named 'App1.exe'. If the App1 gives run time exception, it should be logged by console app and continue the rest.

Please anyone provide an optimal solution or an idea to get the unhandled exceptions's details of the applications which are all providing exception at run time.

Community
  • 1
  • 1
Kathir Subramaniam
  • 1,195
  • 1
  • 13
  • 27

1 Answers1

0

Your options are one or the combination of those:

  • use the return code of your app in you console app
  • catch and log exceptions (like in a file or wathever) from the app itself and process log file in the console app.

Here is the code of a console app that starts another app and waits to get the return code of the app process. If the exception you mention occurs in the app you get an error code of 255, 0 if no error.

    static void Main(string[] args)
    {
        try
        {
            var process = Process.Start("WpfApplication1.exe");
            process.WaitForExit();
            Console.WriteLine("App exited with code " + process.ExitCode);
            Console.ReadKey();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }

If you don't want exceptions to be shown in a UI within the app, you have to catch them in the app itself (and log them to process them in the console app if needed).