473,508 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Raising errors in a catch block in SQL2005

When a catchable error occurs in a try block, control is passed to the
associated catch block. While I am then able to examine properties of
the error using such functions as ERROR_NUMBER() in the catch block,
the error-logging scheme used in my company requires that the actual
error be raised so that it can be picked up by components in the next
tier. I appear to be unable to do that -- I can raise some other error
that has all of the properties of the original except the error number.
For example, division by zero raises error 8134. If the code that
produces that error is enclosed in a try block, I seem to be unable to
raise that error from the catch block. Of course, if I never used the
try block to begin with this wouldn't be a problem, but then we
wouldn't have the advantages of this structure as it applies to other
errors, some of which we may wish to handle differently. While
Try-Catch looks great as a way of allowing us to handle errors in a
customized way and to avoid having all errors be passed up to our
middle tier, it seems that we are unable to pass ANY such errors
forward, and that is a problem for us, too. Is my understanding of
this situation correct, or is there some way around this problem, e.g.,
is there any way I could have raised error 8134, in the above example?
Thanks.

May 2 '06 #1
2 1793
Hi there,

I believe that you can pass errors forward by including a call to the
RAISERROR routine within your CATCH block.

There is an example on how to do this on this webpage:
http://msdn2.microsoft.com/en-US/library/ms179296.aspx

If you have followed the example on that page, then sorry I couldn't be
of more help

May 3 '06 #2
davidz (da****@oz.net) writes:
When a catchable error occurs in a try block, control is passed to the
associated catch block. While I am then able to examine properties of
the error using such functions as ERROR_NUMBER() in the catch block,
the error-logging scheme used in my company requires that the actual
error be raised so that it can be picked up by components in the next
tier. I appear to be unable to do that


Correct. There is no re-raise operation in SQL 2005.

There is a fairly good work around. Just create a custom message, and then
format that message to include all essential information. The middle-tier
components will need to be adapted so if they this particular error number,
for instance 55555, they need to parse the message text to get the
components.

The new error-handling stuff in SQL 2005 is definitely too good to be
ignored!

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1847
by: Rajesh.V | last post by:
I have made a custom control in asp.net using webcontrols, and am raising my event. I find that if no control is hooked into the event it goes for a toss. I tried to find length of the delegate...
3
5100
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library....
11
3460
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
1
1407
by: Klaus Jensen | last post by:
Hi! I often raise my own errors in code, and I just use ErrorNumber 1, since I do not use this number for anything (like maintaining a table of errornumbers or whatever). I then started...
3
1110
by: Jon Turner | last post by:
I have an asynchronous call to a remote procedure that is invoked thru BeginInvoke. The problem is that in the Delegate if I throw an event before the CallBack function exits, the CallBack will...
6
7427
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
2
1844
by: wink | last post by:
Hello, I would like to know what would be considered the most Pythonic way of handling errors when dealing with files, solutions that seem reasonable using 2.5: ------- try: f =...
2
9006
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5633
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.