Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 24th, 2009, 06:14 AM
Registered User
 
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default RAISERROR doesn't cause exception in the .NET client code

Hi,

My impression about RAISERROR(SQL 2005) was that it would cause exception in the client application.

I have a stored proc that uses RAISERROR in the catch block to pass the error from DB layer to the application layer. But the client code throws no exception.

Below is the sample code that i'm using.
Stored Proc:
Code:
CREATE PROCEDURE [dbo].[usp_ThrowException]
AS
BEGIN
   SET NOCOUNT ON;
   BEGIN TRY
       SELECT Col1, 1/0 AS 'Exception', Col2 FROM tblDemo
   END TRY
   BEGIN CATCH
       DECLARE @Err_Msg NVARCHAR(4000), @Err_Severity INT
       SELECT @Err_Msg = ERROR_MESSAGE(),
                    @Err_Severity = ERROR_SEVERITY()
       RAISERROR(@Err_Msg, @Err_Severity, 1)
    END CATCH
END
Client application code:
Code:
//........
try {
     //Code to connect to DB, invoke the SP and 
     //retrieve the records (to be specific, using SqlDataReader to get the data)
}
catch (SqlException sqlEx) {
     Console.WriteLine(string.Format("ErrorCode: {0}, Message: {1}, Number: {2}, State: {3}", sqlEx.ErrorCode, sqlEx.Message, sqlEx.Number, sqlEx.State));
}
catch (Exception oEx) {
     Console.WriteLine(oEx.Message);
}
//..............
Any ideas why no exception is thrown in the client code.

Cheers,
Adarash

Last edited by r_adarsh; March 22nd, 2009 at 08:57 AM..
 
Old March 22nd, 2009, 09:00 AM
Registered User
 
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

132 reads but no reply :-(
Is the question not clear enough?
Guys....anyone?

Cheers,
Adarsh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Axis client throwing exception sometimes chandootechie J2EE 0 March 17th, 2006 07:51 AM
RAISERROR on my ASP.NET Web Application ozzy SQL Server 2000 3 April 17th, 2005 11:29 PM
Writing Client side script in code-behind asp.net sajid_pk ASP.NET 2.0 Basics 1 February 11th, 2005 04:22 AM
Writing client side script in code-behind asp.net sajid_pk ADO.NET 1 January 13th, 2005 08:12 AM
writing client-side script in code-behind asp .net sajid_pk General .NET 1 January 13th, 2005 08:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.