473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Excpetion Handling

Consider this....
public sqldatareader somefunction(){
try
{
sqldatareader sr=sqlcommand.executereader();
return sr;
}
catch
{
throw;
}
}

my question is why bother with try/catch, if I have to throw an exception?
Jul 21 '05 #1
3 1162
In this specific case, you would not gain anything since your catch is not
doing anything other then rethrowing the exception, and you don't have a
finally block.

"mavrick101" <ma********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Consider this....
public sqldatareader somefunction(){
try
{
sqldatareader sr=sqlcommand.executereader();
return sr;
}
catch
{
throw;
}
}

my question is why bother with try/catch, if I have to throw an exception?

Jul 21 '05 #2
Thanks for your response...

So, I'm going to handle the exception at client side (caller of the method).
Just curious , what would be the best way to handle exceptions in this or
similar cases...Any best practices?
"Marina" wrote:
In this specific case, you would not gain anything since your catch is not
doing anything other then rethrowing the exception, and you don't have a
finally block.

"mavrick101" <ma********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Consider this....
public sqldatareader somefunction(){
try
{
sqldatareader sr=sqlcommand.executereader();
return sr;
}
catch
{
throw;
}
}

my question is why bother with try/catch, if I have to throw an exception?


Jul 21 '05 #3
Hi Mavrick,
Check out these links for best practises for exception management..
http://msdn.microsoft.com/library/de...us/dnbda/html/
exceptdotnet.asp

http://www.codeproject.com/dotnet/ex...tpractices.asp

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconbestpracticesforhandlingexceptions.asp

http://www.codeproject.com/dotnet/Be...esExcMgmnt.asp

HTH,

Happy Coding

"mavrick101" <ma********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
Consider this....
public sqldatareader somefunction(){
try
{
sqldatareader sr=sqlcommand.executereader();
return sr;
}
catch
{
throw;
}
}

my question is why bother with try/catch, if I have to throw an exception?

Jul 21 '05 #4

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

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
3
by: Phadnis | last post by:
hi.. iam trying to have a proxy server which listens to the rquests comign from port 80. in tcp listener declaration i have give my system name n the port 80 to listen to. but when i run it...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
by: Stefan Johansson | last post by:
Hi all I'am moving from Visual Foxpro and have a question regarding "best practice" error handling in vb .net. In VFP I have always used a "central" error handling object in order to have a...
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
7
by: yogeshnelwadkar | last post by:
Hello, i have a problem with replacing c++ exception handling with structured exception handling. How to replace the " catch(...) " in c++ exception handling with, __except , a structured...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.