You need to stop mixing "API , was it Zero or something else" mentality with
Exception Handling.
Below is a stab at a rewrite/refactor.
Handle the exception ( a specific exception like IOException and not
"Exception" on the outside calling code.
private string RunTheProcess(SomeObject cfrmTRSobj)
{
StreamReader myStreamReader = null;
ProcessStartInfo myProcessStartInfo = null;
try
{
myProcessStartInfo = new ProcessStartInfo();
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardError = true;
TestProcess.StartInfo = myProcessStartInfo;
TestProcess = Process.Start( MyProcess , " -file "+
cfrmTRSobj.GetTRSFullFileName() );
SetProcID( TestProcess );
TestProcess.WaitForExit();
StreamReader myStreamReader = TestProcess.StandardError; //HUH???
return myStreamReader.ReadToEnd();
}
// purposely, there is no catch statement here
finally
{
//clean up here
if(null!=myStreamReader)
{
myStreamReader.Close();
}
}
}
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Feb 26, 4:42 pm, Eran.Ya...@gmail.com wrote:
> > Hi,
> >
> > My app starts process. Some times this process exits because of
> > exception. Can my app know if the process exited due to exception or
> > gracefully?
> >
> > In both ways, the exit code of this process is zero.
> >
> > I tried using the following, but it goes to catch.
> >
> > ProcessStartInfo myProcessStartInfo = new ProcessStartInfo();
> > try
> > {
> > myProcessStartInfo.UseShellExecute = false;
> > myProcessStartInfo.RedirectStandardError = true;
> > TestProcess.StartInfo = myProcessStartInfo;
> > TestProcess = Process.Start( MyProcess , " -file "+
> > cfrmTRSobj.GetTRSFullFileName() );
> > SetProcID( TestProcess );
> > TestProcess.WaitForExit();
> > StreamReader myStreamReader = TestProcess.StandardError;
> > MessageBox.Show(myStreamReader.ReadToEnd());}
> >
> > catch( Exception e )
> > {
> > bRetval = frmMain.RETVALSTATUS.FAIL;
> > TestStatus = frmMain.DGETestStatusenums.STATUSFAILED;}
> >
> > when the app reached to "StreamReader myStreamReader =
> > TestProcess.StandardError;" it jump to catch.
> >
> > Is there any other way or am I doing any thing wrong?
>
> Ooops, forgot. Thanks for the help. 
>