Results 1 to 8 of 8

Thread: Try....Catch and Performance

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Try....Catch and Performance

    Do try...catch block affects the performance of the application... even tough if exception is never thrown??If yes is it soo significance ?

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Try....Catch and Performance

    I don't believe Try or Finally reduce performance at all (or if they do, it's so tiny that it wouldn't be noticeable). Catch is a little different. Throwing an exception is expensive so when Catch is called, performance is hurt.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Try....Catch and Performance

    Every time a function or sub is invoked there is a passing of control from one program-counter location to another.

    The runtime engine is handling this.

    It's got unavoidable error detection running at all times - so that when an error is thrown and you don't have logic in the error handler the error value can be passed back up to the calling function.

    All this is in place regardless.

    Having an error handler means that you are placing code in a location to be "run through" in the event an error is detected.

    Everytime you choose one syntax construct over another you are introducing additional steps in code that the program counter must move through (or reducing those steps).

    Considering where app performance is hindered is a good thing - but this is certainly not one of them.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Try....Catch and Performance

    One thing that most definately DOES affect an application is NOT having error traps. Regardless of the consequences, some form of error trapping should always be a part of all code.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Try....Catch and Performance

    What platform? What language?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Try....Catch and Performance

    .NET platform and any .NET language

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Try....Catch and Performance

    Regardless, it is better to have it, than not have it.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Try....Catch and Performance

    According to what I read in MSDN, there is no cost for error handling as long as there are no exceptions raised.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width