Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2003
    Posts
    95

    Unanswered: RAISERROR Behavior Question

    I have a RAISERROR statement being displayed to the screen prior to a print statement, however the print statement was executed before the RAISERROR statement. Why would this happen? The print statement is not part of any conditional logic. It is executed sequentially followed by an IF statement that generates the RAISERROR.

    Step 1. Loop through all Databases and dynamically run DBCC ShowContig
    Step 2. End the loop and Print "SCANNING COMPLETED"
    Step 3. Declare Cursor to read DBCC ShowContig results
    Step 4. Check current time to see if it is ok to continue processing
    If it is NOT ok, RAISERROR
    Else begin DBReindex process
    Step 5. Close and Deallocate Cursor

    If I replace RAISERROR with a print statement, everything prints in order. What gives?

    Dave

  2. #2
    Join Date
    Sep 2003
    Location
    KY
    Posts
    146

    You can

    If you post the code it would be easier to find solution. However, If you are not saving the value of @@error in a variable it resets to Zero when you go back to check it again .

    In other words You should

    Declare @err int
    And while checking @@error use Select @err = @@error and then check @err value which will stay stored . I am not sure if this is what you needed to know .. Like I said , code posting might help

  3. #3
    Join Date
    Jan 2003
    Posts
    95
    The logic itself works fine so posting the code most likely won't help. The RAISERROR is generated after a conditional statement checking the length of a local variable. There is no need to check @@ERROR at that time. The only issue is why a RAISERROR gets sent to the screen before a print statement when the print statement executed first. I was told a few hours ago that Print statements are first sent to the buffer and its possible a RAISERROR does not hit the buffer. That may explain why it appears first.

    Thanks, Dave

  4. #4
    Join Date
    Sep 2003
    Posts
    522
    what's the severity level and state values? i've experimented for a couple of minutes with different severity levels including 20 and up, at which point the print statement does not get displayed at all.

  5. #5
    Join Date
    Jan 2003
    Posts
    95
    Raiserror ("My error message", 16, 1) with log

    Dave

  6. #6
    Join Date
    Sep 2003
    Posts
    522
    i put print 'test' before your raiserror and got this:

    test
    Server: Msg 50000, Level 16, State 1, Line 2
    My error message

  7. #7
    Join Date
    Jan 2003
    Posts
    95
    I'll be testing all of the error routines again this week. Once I recreate the issue I'll see if the code is small enough to post.

    Thanks, Dave

Posting Permissions

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