using And Try Catch in harmony

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

    using And Try Catch in harmony

    Whats the best way of handing exception of using?
    Is it method 1 or method 2 or some other way
    ########## Method 1 ###########
    using(something )
    {
    try
    {
    }
    catch
    {
    }

    }

    ########## Method 2 ###########
    using(something )
    {
    try
    {
    }
    catch
    {
    }
    finally
    {
    }

    }
  • Peter Duniho

    #2
    Re: using And Try Catch in harmony

    On Fri, 07 Mar 2008 11:19:34 -0800, parez <psawant@gmail. comwrote:
    Whats the best way of handing exception of using?
    There's no practical difference between the two options that you posted,
    other than the presence of the "finally" block. You'd use "finally" for
    the same reasons you'd use it otherwise: you have something that always
    has to be done before exiting the try/catch/finally section, whether an
    exception occurs or not.

    Obviously, if the only reason you would have had a "finally" block before
    is to dispose the "something" you've put in the "using" statement, then
    you wouldn't need "finally". But otherwise, nothing has changed.

    And next time, please indent any code you post. Thanks.

    Pete

    Comment

    • Robson Felix

      #3
      Re: using And Try Catch in harmony

      I think you rather should put your using clause within the try catch. It
      would make more sense, right?

      "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
      news:op.t7nu3vh z8jd0ej@petes-computer.local. ..
      On Fri, 07 Mar 2008 11:19:34 -0800, parez <psawant@gmail. comwrote:
      >
      >Whats the best way of handing exception of using?
      >
      There's no practical difference between the two options that you posted,
      other than the presence of the "finally" block. You'd use "finally" for
      the same reasons you'd use it otherwise: you have something that always
      has to be done before exiting the try/catch/finally section, whether an
      exception occurs or not.
      >
      Obviously, if the only reason you would have had a "finally" block before
      is to dispose the "something" you've put in the "using" statement, then
      you wouldn't need "finally". But otherwise, nothing has changed.
      >
      And next time, please indent any code you post. Thanks.
      >
      Pete

      Comment

      • Peter Duniho

        #4
        Re: using And Try Catch in harmony

        On Fri, 07 Mar 2008 11:38:56 -0800, Robson Felix <robson@robsonf elix.com>
        wrote:
        I think you rather should put your using clause within the try catch. It
        would make more sense, right?
        It might. It might not. It really depends on what you're trying to do.
        Without seeing of the rest of the code, it's impossible to say, as there's
        no general-purpose rule that applies in all situations.

        Pete

        Comment

        Working...