0

I am creating a Windows Forms application in which I need small help for exception handling.

What my application would do (an overview): Take inputs from the user in the start. When the user clicks on the Finish button, the inputs are processed. Based on the inputs given, certain computations are performed. After this, an application is uninstalled using msiexec /x command (being launched as a separate process).

If there is an exception during the input processing time (that is, before the uninstall task), I am calling the Application.Exit() method. Following code snippet might give you an idea:

try
{
    //some processing
}
catch (Exception exc)
{
    DisplayErrorMessage();
    WriteToLog(exc.Message);
    WriteToLog("Inner Exception: " + exc.InnerException);
    Application.Exit();
}

My Observation: If any exception was encountered during the processing time, the Process.Start() method is returning null.

Can somebody tell why this is happening? Is there a way to overcome this?

P.S: How do i need to modify my code so that, if an exception occurs previously, the process doesn't even start?

RisingHerc
  • 694
  • 1
  • 9
  • 26

1 Answers1

0

I have figured out that calling Environment.Exit(1) actually terminates the forms application, which is not done by calling the Application.Exit() method.

More information can be obtained from the following link: How to properly exit a C# application?

RisingHerc
  • 694
  • 1
  • 9
  • 26