﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / RAISERROR in TRY/Catch block after XML Schema Collection Validation. / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 18 May 2013 23:30:08 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: RAISERROR in TRY/Catch block after XML Schema Collection Validation.</title><link>http://www.sqlservercentral.com/Forums/Topic690090-338-1.aspx</link><description>How about this approach?[code]DECLARE @EmpXML AS XML(EmployeeSchema) DECLARE @LocalError  -- as what?BEGIN TRY   SET @EmpXML = @EmployeeXML -- TRY to set the @EmpXML to @EmployeeXML END  Try BEGIN  CATCH   -- If the attempt fails, then   SET @LocalError = 50001 --user defined error   RAISERROR(' The input parameter @EmployeeXML is not valid', 16, 1)END[/code]</description><pubDate>Fri, 03 Apr 2009 22:33:32 GMT</pubDate><dc:creator>The Dixie Flatline</dc:creator></item><item><title>RE: RAISERROR in TRY/Catch block after XML Schema Collection Validation.</title><link>http://www.sqlservercentral.com/Forums/Topic690090-338-1.aspx</link><description>Hit Matt,Thanks for you feedback.Actually yes, I am already doing that in my Unit Test for the from as shown below, but still no luck--Set the values for the Input variablesDECLARE @EmpXML XML = 'Test',@ErrorMsg varchar(200)BEGIN TRYEXEC @rc = dbo.ImportEmployeeInfo	@EmployeeXML = @EmpXML END TRYBEGIN CATCH    SELECT @Error = ERROR_MESSAGE()END CATCHSELECT @Error AS Error</description><pubDate>Fri, 03 Apr 2009 15:18:07 GMT</pubDate><dc:creator>bdba</dc:creator></item><item><title>RE: RAISERROR in TRY/Catch block after XML Schema Collection Validation.</title><link>http://www.sqlservercentral.com/Forums/Topic690090-338-1.aspx</link><description>The error handling and the error catching in SQL 2005 can be tricky.  Depending on the erro you might be facing, it may be "batch" or "thread" terminating, meaning the inner context cannot catch anything, since it's been terminated.The TRY...CATCH routines inside the stored proc can catch a lot of the minor non terminating errors.  If you want to catch more errors than that - try wrapping your CALL to the stored proc in a TRY....CATCH.  That way you can g etall the detail you need.</description><pubDate>Fri, 03 Apr 2009 14:27:53 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RAISERROR in TRY/Catch block after XML Schema Collection Validation.</title><link>http://www.sqlservercentral.com/Forums/Topic690090-338-1.aspx</link><description>Posted this earlier under SQL 7, 2000 T-SQL Section. Have deleted that one and reposting under SQL 2005.I am trying to Raise an error using RAISERROR function in sql when the XML schema validation fails.I am doing this inside a store proc. I am declaring the XML doc binding it to it's XSD schema in the TRY block and if validation fails, raise a user define error number by using RAISERROR function in the catch block. However, somehow i am not able to do this and sql return it's own error the moment it executes that line of code. So using Employee example here, I am doing something like this.CREATE PROC ImportEmployeeInfo@EmployeeXML as XMLASBEGINBEGIN TRYDECLARE @EmpXML AS XML(EmployeeSchema) --declaring a local XML variable and binding it to its XSD Schema CollectionDECLARE @LocalErrorSET @EmpXML = @EmployeeXML -- here I am setting the @EmpXML to @EmployeeXML variable passed inIF @@error&amp;lt;&amp;gt;0 --if the @EmployeeXML failed the XSD validation, i beileve there would be an error right however this line never gets executedBEGINSET @LocalError = 50001 --user defined errorRAISERROR(' The input parameter @EmployeeXML is not valid', 16, 1)END--The XML shredding and import into table goes hereEND TRYBEGIN CATCH--I have another another user defined errorhandler proc here which will take the above @LocalError --as input parameter and raise a detailed errorEND CATCHEND --End of Proc</description><pubDate>Fri, 03 Apr 2009 10:55:57 GMT</pubDate><dc:creator>bdba</dc:creator></item></channel></rss>