How to catch all exceptions?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • K Viltersten

    #1

    How to catch all exceptions?

    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.StartIn fo.UseShellExec ute = false;
    process.StartIn fo.RedirectStan dardError = true;
    process.StartIn fo.FileName = "c:\javaws.exe" ;
    process.StartIn fo.Arguments = options;
    process.Start() ;
    }
    catch (Exception exception){
    Logger.WriteLog (exception.Mess age);
    }
    }

    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

    #2
    Re: How to catch all exceptions?

    process.StartIn fo.UseShellExec ute = false;
    process.StartIn fo.RedirectStan dardError = true;
    process.StartIn fo.FileName = "c:\javaws.exe" ;
    process.StartIn fo.Arguments = options;
    process.Start() ;
    I've noticed also that when i logged
    process.StartIn fo.RedirectStan dardError
    process.Standar dError.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.


    Comment

    • Peter Duniho

      #3
      Re: How to catch all exceptions?

      On Mon, 22 Sep 2008 22:57:24 -0700, K Viltersten <tmp1@vilterste n.com>
      wrote:
      I've noticed also that when i logged
      process.StartIn fo.RedirectStan dardError
      process.Standar dError.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

      Comment

      • K Viltersten

        #4
        Re: How to catch all exceptions?

        >I've noticed also that when i logged
        > process.StartIn fo.RedirectStan dardError
        > process.Standar dError.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.


        Comment

        • Peter Duniho

          #5
          Re: How to catch all exceptions?

          On Tue, 23 Sep 2008 00:16:33 -0700, K Viltersten <tmp1@vilterste n.com>
          wrote:
          [...]
          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

          Comment

          Working...