Testing TRY...CATCH in SQL Server Management Studio


I've misinterpreted the example from SQL Books Online. Yes, that below the section Errors Unaffected by a TRY…CATCH Construct ... I'm so sorry :(

I was just trying to execute this simple example in SQL Server Management Studio:

USE AdventureWorks;

    -- Table does not exist; object name resolution
    -- error not caught.
    SELECT * FROM NonexistentTable;
        ERROR_NUMBER() as ErrorNumber,
        ERROR_MESSAGE() as ErrorMessage;

But the only thing I find as output is:

Msg 208, Level 16, State 1, Line 5 Invalid object name 'NonexistentTable'.

So, the error seems to be captured by the SQL Server Management Studio instead of the catch block, which is obviously not what I expected. Am I missing something?

Thanks in advance :)


Your first example is used in the SQL Books Online, did you copy it from there? If so, read the entire topic and you'll see that this indeed will not work. The error is not raised by Management Studio, it is a name resolution error and that will simply not be caught by a TRY/CATCH block.

Need Your Help

Let git bash launch at current repositories

windows git git-extensions git-bash

Is there a way to let Git Extension open Git Bash at the current repositories ?

Zend Framework under Ubuntu 11.10: internal server error with virtual server

ubuntu zend-framework apache2

I'm having a strange problem with Zend Framework under Ubuntu 11.10. I'm using a laptop as my programming environment to test out some things before uploading them to my main server. I downloaded ...