473,669 Members | 2,466 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 1801
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****@sommarsk og.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
1857
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 array returned by ButtonClicked.GetInvocationList method event that is raising an exception. Presently i am enclosing in try catch block and would like to avoid that. Any suggestions on how to find if any body is hooked/listening to this event.
3
5126
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. When i try to connect to a server that doesnt exist it raises a "Connection forcibly rejected by the resmote host" SocketException.
11
3475
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
1412
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 wondering... Is this an okay use of raising errors? Should I use a certain range of numbers for some reason? Is there a best practice for raising errors - things to consider?
3
1117
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 get called multiple times and error out with the following Error: <EndInvoke can only be called once for each asynchronous operation.> If I comment out the RaiseEvent, then the Callback exits with a single call to EndDelegate.
6
7441
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. The question is: after the ThreadAbortException is thrown, does the childThread continue run the remaining code in the catch block?
2
1853
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 = open('afile', 'r') content = f.read()
2
9031
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 figure this problem out. Any suggestions? thanks Joel
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8895
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4206
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
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 we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.