How to catch all exceptions?

K

K Viltersten

I've developed a service and protected it's
contents from presenting the potential error
messages by a number of try-catch statements,
especially a general, top level try-catch.

When i run it, i sometimes get errors to the
screen anyway, which depends (i suspect) on
the fact that i execute external EXE's. How
can i make perfectly sure not to show
anything to the screen but report all
exceptions back to the try-catch so i can
log them? I've done the following.

public void RunMe(){
Process process = null;
try{
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "c:\javaws.exe";
process.StartInfo.Arguments = options;
process.Start();
}
catch (Exception exception){
Logger.WriteLog(exception.Message);
}
}

Is it possible? What have i missed?
 
K

K Viltersten

process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.FileName = "c:\javaws.exe";
process.StartInfo.Arguments = options;
process.Start();

I've noticed also that when i logged
process.StartInfo.RedirectStandardError
process.StandardError.ToString())
i got "True" on the first one (as expected) but i
cause an error on the second one. The error message
is that the standard error has not been redirected.
What's up with that?!
 
K

K Viltersten

I've noticed also that when i logged
Hard to say, since you didn't post a complete code example. But, had you
started the process when you tried to get the StandardError stream? If
not, I believe that would explain your failure.

As far as capturing errors generated by other processes, there's not any
accepted mechanism in .NET that I know of to do that. You can hack
Windows to do anything you want, of course. But as a general rule, your
process doesn't get to override behavior in other processes, including
suppressing error dialogs/messages.

I'm not so much looking for suppressing/overriding the
error behavior. Rather, i'm looking for a way to catch
them in my application. It seems useful to be able to
intercept the error messages produced by a process
that i've started. Can one EXECUTE that process in
such a way so that it will be "catchable"?

It seems like a thing that one would like to have...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top