question

jinverso avatar image
jinverso asked

dm_fts_parser inside try-catch block

Hi, I'm working on a project and have a code similar to the code posted below and I would like to understand why the CATCH block is never executed. If the try catch is removed the dm_fts_parser will send an error complaining search string syntax, however inside a try-catch block the code will silently return an empty recordset, no error is triggered and catch block is never executed.

USE master

DECLARE	@StopWordListID int
	     , @SearchString varchar(1000)
	     , @WordBreakerLcid int
	     , @AccentSensitivity bit
				
SELECT	@SearchString = '"Introduction" OR "Repair and Service'
	    , @WordBreakerLcid = 1033 -- English word breaker
	    , @AccentSensitivity = 0 -- Default is not accent sensitive

SELECT	@StopWordListID = ft.stoplist_id
FROM	AdventureWorks2008.sys.tables t
INNER JOIN AdventureWorks2008.sys.fulltext_indexes ft ON ( t.object_id = ft.object_id )
WHERE	( t.name = 'Document' )

BEGIN TRY
        SELECT	dfp.keyword , LEFT ( dfp.special_term , 200 ) 
        FROM	AdventureWorks2008.sys.dm_fts_parser ( @SearchString , @WordBreakerLcid ,@StopWordListID , @AccentSensitivity ) dfp  

PRINT 'Ok'
END TRY
BEGIN CATCH
           PRINT 'Error'
END CATCH

error-trap
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

WilliamD avatar image
WilliamD answered
If you read up on [Try...Catch in Books Online][1] it explains what is caught using this error handler. There are a few errors that are basically ignored. It sounds like you are having the error being ignored due to TRY...CATCH ignoring syntax errors. Please add a line like `SELECT 1/0` inside the TRY block. This will cause a divide by zero error that will be caught by the CATCH block. This will show you that the TRY...CATCH methodology works as expected. [1]: http://msdn.microsoft.com/en-us/library/ms175976.aspx
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot Hauder avatar image
Scot Hauder answered
Interesting, looks like a bug to me. It is clearly a level 15 error. If it is running at a lower batch level then executing it within a stored proc should produce the error--but that is not the case either
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Scot - I understood the description to mean he was having syntax errors in his code. As I don't hat FT installed I couldn't check that.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.