|
List Info
Thread: C-Sharp (C#) Group: to try or not to try....
|
|
| C-Sharp (C#) Group: to try or not to
try.... |

|
2006-11-07 21:29:24 |
This is a philosophical question and one that I have been
struggling
with and could use other, saner minds and their feedback.
I read in most of the manuals, and tutorials that basically
everything
should be wrapped in a try, catch block. In other words all
possible
exception should be handled, and not let to surprise the
client. Now on
the surface this seems perfectly reasonable to me in one
sense, I mean
it just makes good stewardship to catch any possible
exceptions that
might pop up and then either handle them or end the program
gracefully
and log the errors. On the other hand that means that 1.) I
am going to
have a ton of try, catch (and possibly even try catch
throws) in my
code, it would seem to me that this would add to clutter and
reduce
readability. I also have to wonder how in the world I am
supposed to
know and record every possible exception that a particular
method might
throw... I know I know ... I do not have to explicitly state
each and
every one but can catch a generic, but then that seems to be
a bit more
ineffective since I do not know anything about what is
popping up.
I also wonder about the performance hit this bullet proof
code is going
to take for the entire try, catch, throw statements; surely
they have
some detrimental effect?
This is where I can use you, my more learned, more
experience and wiser
friend... how can I make sense of all this, what is the
better way, or
the best practice, and why?
What do you do?
I appreciate any and all help and discussion
Thanks
-SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-08 16:52:24 |
I think the idea is to catch the errors you expect to find -
so io
error in file opperations etc. The reasoning behind this is
to allow a
betteruser experiance - so in an IO error you could report
that the
file is locked (assuming you checked it was there in the
first place!)
If you do nothing with the error other than display a
standard message
to the user then I cant see the point in catching the
differant
possiblities tbh.
Not sure what differance it makes from a performance pov.
Ross
On Nov 7, 9:29 pm, "SteveM" <steve.mo... philips.com> wrote:
> This is a philosophical question and one that I have
been struggling
> with and could use other, saner minds and their
feedback.
>
> I read in most of the manuals, and tutorials that
basically everything
> should be wrapped in a try, catch block. In other words
all possible
> exception should be handled, and not let to surprise
the client. Now on
> the surface this seems perfectly reasonable to me in
one sense, I mean
> it just makes good stewardship to catch any possible
exceptions that
> might pop up and then either handle them or end the
program gracefully
> and log the errors. On the other hand that means that
1.) I am going to
> have a ton of try, catch (and possibly even try catch
throws) in my
> code, it would seem to me that this would add to
clutter and reduce
> readability. I also have to wonder how in the world I
am supposed to
> know and record every possible exception that a
particular method might
> throw... I know I know ... I do not have to explicitly
state each and
> every one but can catch a generic, but then that seems
to be a bit more
> ineffective since I do not know anything about what is
popping up.
>
> I also wonder about the performance hit this bullet
proof code is going
> to take for the entire try, catch, throw statements;
surely they have
> some detrimental effect?
>
> This is where I can use you, my more learned, more
experience and wiser
> friend... how can I make sense of all this, what is the
better way, or
> the best practice, and why?
>
> What do you do?
>
> I appreciate any and all help and discussion
> Thanks
> -SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 01:24:58 |
try/catches are a good thing most of the time. You do not
want to
overpopulate your code with them. Generally, I will wrap
anything that
could throw an exception with a try/catch to gracefully
handle them
instead of having the program crash. I usually include the
pdb
(program database) files to help point me in the right area
of the
bug/issue. This is totally up to you if you want people
knowing more
about the code. I also generally log this in the system
event log.
Basically, you do not want your program crashing on you
because someone
enter a character instead of an integer to a text field or
pointed to a
wrong location for a file. Instead display a message and
allow the
user to fix the error and try the operation again.
As far as performance, it will slow down the process. In
other words,
avoid putting a try/catch in a for loop...or you can try and
see how
much it slows things down. Generally, if you have a single
try/catch
wrapped around the process, you will not see much as far as
performance
issues. If you start putting try/catches around every other
line in
your code, you will see things drag.
Basically, try/catches are good as long as you use them
properly.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 01:50:44 |
|
One of the big issues is that you DON'T attempt to catch every possible
known exception to man. For example, when working with Sql Server, the
possible exceptions that can arise fall into 2 categories, SqlException
and Exception (the general case). When your code is fine grained
enough, you will NOT ever hit the general exception case. If you do,
you know there's something wrong with your code model. SqlExceptions
can happen though for any number of reasons. That said, sometimes you
simply will not know what exceptions might arise, and so one uses the
general exception Exception.
With regards to performance, check out this article on www.developerland.com
it'll answer 99% of your questions.
M
RossD wrote:
m73g2000cwd.googlegroups.com"
type="cite">
I think the idea is to catch the errors you expect to find - so io
error in file opperations etc. The reasoning behind this is to allow a
betteruser experiance - so in an IO error you could report that the
file is locked (assuming you checked it was there in the first place!)
If you do nothing with the error other than display a standard message
to the user then I cant see the point in catching the differant
possiblities tbh.
Not sure what differance it makes from a performance pov.
Ross
On Nov 7, 9:29 pm, "SteveM" philips.com"><steve.mo... philips.com> wrote:
This is a philosophical question and one that I have been struggling
with and could use other, saner minds and their feedback.
I read in most of the manuals, and tutorials that basically everything
should be wrapped in a try, catch block. In other words all possible
exception should be handled, and not let to surprise the client. Now on
the surface this seems perfectly reasonable to me in one sense, I mean
it just makes good stewardship to catch any possible exceptions that
might pop up and then either handle them or end the program gracefully
and log the errors. On the other hand that means that 1.) I am going to
have a ton of try, catch (and possibly even try catch throws) in my
code, it would seem to me that this would add to clutter and reduce
readability. I also have to wonder how in the world I am supposed to
know and record every possible exception that a particular method might
throw... I know I know ... I do not have to explicitly state each and
every one but can catch a generic, but then that seems to be a bit more
ineffective since I do not know anything about what is popping up.
I also wonder about the performance hit this bullet proof code is going
to take for the entire try, catch, throw statements; surely they have
some detrimental effect?
This is where I can use you, my more learned, more experience and wiser
friend... how can I make sense of all this, what is the better way, or
the best practice, and why?
What do you do?
I appreciate any and all help and discussion
Thanks
-SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group. To post to this group, send email to C_Sharp googlegroups.com To unsubscribe from this group, send email to C_Sharp-unsubscribe googlegroups.com For more options, visit this group at http://groups-beta.google.com/group/C_Sharp?hl=en -~----------~----~----~----~------~----~------~--~---
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 02:12:56 |
Great Article thanks
-SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 02:14:41 |
Thanks Tsito for the information.
I appreciate everyone who has taken the time to post and
clear the cob
webs
Thanks
-SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 02:13:39 |
Thanks for the insite Ross I appreciate it
-SteveM
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| C-Sharp (C#) Group: Re: to try or not to
try.... |

|
2006-11-09 03:38:27 |
np dude, glad it helped.
SteveM wrote:
> Great Article thanks
> -SteveM
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups-beta.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-8]
|
|