try catch costs vs @@Error

  • Hi,

    I am working with sql-server 2005 since a few weeks, (before it was sql2000), and there is one advantage I'd like to use, and that is the try...catch instead of @@Error

    But I have one very important question: If I use try catch, will I lose performance? I have noticed when I use functions that are written in CLR, they are slower, will this also be the case with try...catch?

    Maybe I had to post this in de CLR group, I do not know...

    Best regards,

    Mischa

  • Mischa E.J. Hoogendoorn (11/12/2008)


    Hi,

    I am working with sql-server 2005 since a few weeks, (before it was sql2000), and there is one advantage I'd like to use, and that is the try...catch instead of @@Error

    But I have one very important question: If I use try catch, will I lose performance? I have noticed when I use functions that are written in CLR, they are slower, will this also be the case with try...catch?

    Maybe I had to post this in de CLR group, I do not know...

    Best regards,

    Mischa

    @@Error is more faster

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • It will depend on the situation. If, for instance, you have 10 inserts and you need to check @@Error after each one, using one TRY-CATCH block will be faster, cleaner, and less code. If you put an individual TRY-CATCH around each insert, checking @@Error may actually be faster (although I am not sure it would be).

    In most cases, you should change over to the TRY-CATCH syntax for error handling.

    Oh, and on the CLR procedures and functions. This will depend on the situation. First, there are some things that cannot be done with T-SQL but can be with the CLR. Also, the CLR will tend to perform better than T-SQL for operations that require "loop and repeat" operations. Always try to use the most appropriate tool.

  • thanks for your time, I think that the answers given are helping me a lot!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply