Errortrap in sp

  • Hi friends,

    i m back after a long gap with a good question(i think so)..

    Can we use errtrap in a sp to trap the errors which occurs inside it...Hope it can b done, So Guru's clarify my doubt with examples..

  • error trapping in TSQL is pretty limited;

    if an error is level 16 or above(foreign key constraint violations, primary key, etc), they raise an error that cannot be trapped in TSQL, which is often the exact kind of errors you want to raise.

    if you raise your own errorsthat are less than level 16, you could capture those, but that might not be all that helpful;

    for example, you could test a value to see if it was less than zero, and then raise an error, but if you were going to raise an error, why wouldn't you just do the logic in the TSQL statement to resolve the issue.

    SQL 20005 actually allows you to do try-catch statements or more robust error validation.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanq lowell

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

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