Error from CREATE ENDPOINT cannot be caught with TRY-CATCH - by Erland Sommarskog

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 1052540 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 12/11/2014 12:33:24 PM
Access Restriction Public


I wanted to create an endpoint for Service Broker programmatically, and if the chosen port was in use, I wanted to try the next one and so own. I wrote some standard error-handling code with TRY-CATCH to trap the condition, but this did not work, because TRY-CATCH does not catch this error. Furthermore @@error comes out 0 if the statement is within TRY-CATCH
Sign in to post a comment.
Posted by Microsoft on 1/13/2015 at 10:43 AM
Thanks for submitting this feedback.

What happens here is that the statement actually succeeds and the endpoint is in fact created; you can verify this in the catalog views.
It is just that subsequent startup fails if there is another process using the same port, and it is this that triggers the error message you are seeing. If that other process goes away before the next time startup is triggered, for example on server restart, then the endpoint you just created will start succesfully.

Jos de Bruijn - SQL Server PM