Connecting Tech Pros Worldwide Forums | Help | Site Map

How to catch all exceptions?

K Viltersten
Guest
 
Posts: n/a
#1: Sep 23 '08
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?

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.



K Viltersten
Guest
 
Posts: n/a
#2: Sep 23 '08

re: How to catch all exceptions?


process.StartInfo.UseShellExecute = false;
Quote:
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?!

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.


Peter Duniho
Guest
 
Posts: n/a
#3: Sep 23 '08

re: How to catch all exceptions?


On Mon, 22 Sep 2008 22:57:24 -0700, K Viltersten <tmp1@viltersten.com>
wrote:
Quote:
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?!
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.

Pete
K Viltersten
Guest
 
Posts: n/a
#4: Sep 23 '08

re: How to catch all exceptions?


>I've noticed also that when i logged
Quote:
Quote:
> 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?!
>
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...

--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.


Peter Duniho
Guest
 
Posts: n/a
#5: Sep 23 '08

re: How to catch all exceptions?


On Tue, 23 Sep 2008 00:16:33 -0700, K Viltersten <tmp1@viltersten.com>
wrote:
Quote:
[...]
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"?
That depends on how much you know about the other application. There's
probably a window hook somewhere that would allow you to watch the windows
the other application displays. If you have sufficient knowledge of what
an error window in that application looks like as compared to a normal UI
window, then you might be able to approach it that way.

And of course, it certainly is possible to redirect the standard error
stream when done correctly, so if the other application emits errors that
way, you can watch for them easily using the Process class.

Other than that, no...there's no really any canonical way for monitoring
another application for errors. There are lots of ad hoc ways to do it,
but nothing reliable.

Pete
Closed Thread