473,480 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Looking for Tips/Writeup on overall approach to Exception Processing

Rex

Re: Looking for Tips/Writeup on overall approach to Exception
Processing

Hi All - I am fairly new to C# and am wondering how to best implement
(overall) Exception Processing within my (reasonably-sized) C# Windows
application. I do have a bunch of somewhat random questions on this
and if you can help me with only one or a few, that would still be
APPRECIATED. Here are my questions:

1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?

2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way? And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!) And should the error message that the User sees always
come from the called routine? And does this mean I would implement a
Try block in every called method??? I would very much appreciate
anyone who can help me sort all of this out... which brings me to...

3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?

Thanks!

Rex
Jun 7 '07 #1
14 1486
On Thu, 07 Jun 2007 14:43:34 -0700, Rex <Re**********@OneSimpleHabit.com>
wrote:
1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?
I don't know what's recommended. But I wouldn't bother, unless I had some
specific sort of cleanup-before-exit stuff I had to make sure happened, or
if my application had some way to sensibly recover from an exception
*instead* of exiting.

After all, if you have no special cleanup to do, and all you're going to
do is catch the exception and then exit, then that's what Windows does for
you already. :)
2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?
I don't think so, not in .NET. I still have methods that return boolean
results, but they do so only in what are considered normal situations. I
would not write a method that returns a boolean, but which should in
theory never return "false" (or "true", depending on how you define the
result :) ). That seems like a waste to me, and is exactly the kind of
situation in which exceptions are useful.

After all, if your method returns a value that should always be "true",
but you require the caller to check the return value, where is the benefit
in that? What is the caller supposed to do with an invalid return value?
Propogate the value back to the caller? Isn't that what exceptions do for
you already?
And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)
See above. :)
And should the error message that the User sees always
come from the called routine?
Another benefit of exceptions is that they can be specific to what went
wrong. Sometimes it is useful to use the InnerException to wrap an
exception in another exception. This would aid, for example, in having an
exception include both the fact that there was some i/o error, as well as
the fact that the i/o error occurred while trying to perform some
higher-level application operation (the InnerException would be the one
thrown by the file access class, like FileStream for example, while the
wrapping exception would be thrown by the higher-level application code
that was trying to do some operation).
And does this mean I would implement a
Try block in every called method???
You should only implement a try/catch block if you can do something with
the exception. It is pointless to catch an exception only to just rethrow
it. In some cases, you may need to do some cleanup, which would be
another reason to catch the exception, but most of the time any cleanup
you need to do can be handled automatically by the "using" statement with
objects that implement IDisposable.
I would very much appreciate
anyone who can help me sort all of this out... which brings me to...

3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?
Not off-hand, no. But I'm sure they are out there. :)

Pete
Jun 7 '07 #2
On Jun 8, 4:52 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 07 Jun 2007 14:43:34 -0700, Rex <RexForum4...@OneSimpleHabit.com>
wrote:
1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?

I don't know what's recommended. But I wouldn't bother, unless I had some
specific sort of cleanup-before-exit stuff I had to make sure happened, or
if my application had some way to sensibly recover from an exception
*instead* of exiting.

After all, if you have no special cleanup to do, and all you're going to
do is catch the exception and then exit, then that's what Windows does for
you already. :)
2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?

I don't think so, not in .NET. I still have methods that return boolean
results, but they do so only in what are considered normal situations. I
would not write a method that returns a boolean, but which should in
theory never return "false" (or "true", depending on how you define the
result :) ). That seems like a waste to me, and is exactly the kind of
situation in which exceptions are useful.

After all, if your method returns a value that should always be "true",
but you require the caller to check the return value, where is the benefit
in that? What is the caller supposed to do with an invalid return value?
Propogate the value back to the caller? Isn't that what exceptions do for
you already?
And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)

See above. :)
And should the error message that the User sees always
come from the called routine?

Another benefit of exceptions is that they can be specific to what went
wrong. Sometimes it is useful to use the InnerException to wrap an
exception in another exception. This would aid, for example, in having an
exception include both the fact that there was some i/o error, as well as
the fact that the i/o error occurred while trying to perform some
higher-level application operation (the InnerException would be the one
thrown by the file access class, like FileStream for example, while the
wrapping exception would be thrown by the higher-level application code
that was trying to do some operation).
And does this mean I would implement a
Try block in every called method???

You should only implement a try/catch block if you can do something with
the exception. It is pointless to catch an exception only to just rethrow
it. In some cases, you may need to do some cleanup, which would be
another reason to catch the exception, but most of the time any cleanup
you need to do can be handled automatically by the "using" statement with
objects that implement IDisposable.
I would very much appreciate
anyone who can help me sort all of this out... which brings me to...
3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?

Not off-hand, no. But I'm sure they are out there. :)

Pete
Some best practices from MSDN:
http://msdn2.microsoft.com/en-us/lib...ts(VS.71).aspx

And some fundementals:http://msdn2.microsoft.com/en-us/library/
2w8f0bss(VS.71).aspx

Again we have many links for best practices posted by developers:
http://www.codeproject.com/dotnet/ex...tpractices.asp
http://www.c-sharpcorner.com/UploadF...anagement.aspx

Jun 8 '07 #3
Rex
Hi Peter and Aneesh,
Thank you both your input - they were both helpful in their own way!
Peter, a couple of points: 1. The advantage of putting a universal
"try/catch" statement in the Main method is that the User does not get
the awful-looking message which asks the User if they wish to SEND the
error to Microsoft. It might be the very same message but it doesn't
look as bad. 2. I've been thinking of this issue for the last 24
hours, and I think I have an interesting solution, as least as
something to try: I'm going to create a static (global) variable (a
string array probably) and call it something like CurrMethodName. Then
at the top of most or every method, I'm going to set its value to the
name of the current method. Then I'll do the Main-level universal
Try/Catch, and display both the error message AND the value in the
string (for diagnostic purposes). If you or anyone has further
thoughts on this, I am open! Thanks again,
Rex
On Fri, 08 Jun 2007 07:38:09 -0000, "Aneesh Pulukkul[MCSD.Net]"
<an******@gmail.comwrote:
>On Jun 8, 4:52 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
>On Thu, 07 Jun 2007 14:43:34 -0700, Rex <RexForum4...@OneSimpleHabit.com>
wrote:
1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?

I don't know what's recommended. But I wouldn't bother, unless I had some
specific sort of cleanup-before-exit stuff I had to make sure happened, or
if my application had some way to sensibly recover from an exception
*instead* of exiting.

After all, if you have no special cleanup to do, and all you're going to
do is catch the exception and then exit, then that's what Windows does for
you already. :)
2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?

I don't think so, not in .NET. I still have methods that return boolean
results, but they do so only in what are considered normal situations. I
would not write a method that returns a boolean, but which should in
theory never return "false" (or "true", depending on how you define the
result :) ). That seems like a waste to me, and is exactly the kind of
situation in which exceptions are useful.

After all, if your method returns a value that should always be "true",
but you require the caller to check the return value, where is the benefit
in that? What is the caller supposed to do with an invalid return value?
Propogate the value back to the caller? Isn't that what exceptions do for
you already?
And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)

See above. :)
And should the error message that the User sees always
come from the called routine?

Another benefit of exceptions is that they can be specific to what went
wrong. Sometimes it is useful to use the InnerException to wrap an
exception in another exception. This would aid, for example, in having an
exception include both the fact that there was some i/o error, as well as
the fact that the i/o error occurred while trying to perform some
higher-level application operation (the InnerException would be the one
thrown by the file access class, like FileStream for example, while the
wrapping exception would be thrown by the higher-level application code
that was trying to do some operation).
And does this mean I would implement a
Try block in every called method???

You should only implement a try/catch block if you can do something with
the exception. It is pointless to catch an exception only to just rethrow
it. In some cases, you may need to do some cleanup, which would be
another reason to catch the exception, but most of the time any cleanup
you need to do can be handled automatically by the "using" statement with
objects that implement IDisposable.
I would very much appreciate
anyone who can help me sort all of this out... which brings me to...
3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?

Not off-hand, no. But I'm sure they are out there. :)

Pete

Some best practices from MSDN:
http://msdn2.microsoft.com/en-us/lib...ts(VS.71).aspx

And some fundementals:http://msdn2.microsoft.com/en-us/library/
2w8f0bss(VS.71).aspx

Again we have many links for best practices posted by developers:
http://www.codeproject.com/dotnet/ex...tpractices.asp
http://www.c-sharpcorner.com/UploadF...anagement.aspx
Jun 8 '07 #4
Consult documentation on Exception.StackTrace property. You
could print this out (instead of capturing the name of the method upon entry
to each function).
"Rex" <Re**********@OneSimpleHabit.comwrote in message
news:hj********************************@4ax.com...
Hi Peter and Aneesh,
Thank you both your input - they were both helpful in their own way!
Peter, a couple of points: 1. The advantage of putting a universal
"try/catch" statement in the Main method is that the User does not get
the awful-looking message which asks the User if they wish to SEND the
error to Microsoft. It might be the very same message but it doesn't
look as bad. 2. I've been thinking of this issue for the last 24
hours, and I think I have an interesting solution, as least as
something to try: I'm going to create a static (global) variable (a
string array probably) and call it something like CurrMethodName. Then
at the top of most or every method, I'm going to set its value to the
name of the current method. Then I'll do the Main-level universal
Try/Catch, and display both the error message AND the value in the
string (for diagnostic purposes). If you or anyone has further
thoughts on this, I am open! Thanks again,
Rex
On Fri, 08 Jun 2007 07:38:09 -0000, "Aneesh Pulukkul[MCSD.Net]"
<an******@gmail.comwrote:
>>On Jun 8, 4:52 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
>>On Thu, 07 Jun 2007 14:43:34 -0700, Rex
<RexForum4...@OneSimpleHabit.com>
wrote:

1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?

I don't know what's recommended. But I wouldn't bother, unless I had
some
specific sort of cleanup-before-exit stuff I had to make sure happened,
or
if my application had some way to sensibly recover from an exception
*instead* of exiting.

After all, if you have no special cleanup to do, and all you're going to
do is catch the exception and then exit, then that's what Windows does
for
you already. :)

2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?

I don't think so, not in .NET. I still have methods that return boolean
results, but they do so only in what are considered normal situations.
I
would not write a method that returns a boolean, but which should in
theory never return "false" (or "true", depending on how you define the
result :) ). That seems like a waste to me, and is exactly the kind of
situation in which exceptions are useful.

After all, if your method returns a value that should always be "true",
but you require the caller to check the return value, where is the
benefit
in that? What is the caller supposed to do with an invalid return
value?
Propogate the value back to the caller? Isn't that what exceptions do
for
you already?

And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)

See above. :)

And should the error message that the User sees always
come from the called routine?

Another benefit of exceptions is that they can be specific to what went
wrong. Sometimes it is useful to use the InnerException to wrap an
exception in another exception. This would aid, for example, in having
an
exception include both the fact that there was some i/o error, as well
as
the fact that the i/o error occurred while trying to perform some
higher-level application operation (the InnerException would be the one
thrown by the file access class, like FileStream for example, while the
wrapping exception would be thrown by the higher-level application code
that was trying to do some operation).

And does this mean I would implement a
Try block in every called method???

You should only implement a try/catch block if you can do something with
the exception. It is pointless to catch an exception only to just
rethrow
it. In some cases, you may need to do some cleanup, which would be
another reason to catch the exception, but most of the time any cleanup
you need to do can be handled automatically by the "using" statement
with
objects that implement IDisposable.

I would very much appreciate
anyone who can help me sort all of this out... which brings me to...

3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?

Not off-hand, no. But I'm sure they are out there. :)

Pete

Some best practices from MSDN:
http://msdn2.microsoft.com/en-us/lib...ts(VS.71).aspx

And some fundementals:http://msdn2.microsoft.com/en-us/library/
2w8f0bss(VS.71).aspx

Again we have many links for best practices posted by developers:
http://www.codeproject.com/dotnet/ex...tpractices.asp
http://www.c-sharpcorner.com/UploadF...anagement.aspx

Jun 8 '07 #5
On Fri, 08 Jun 2007 12:19:39 -0700, Rex <Re**********@OneSimpleHabit.com>
wrote:
Peter, a couple of points: 1. The advantage of putting a universal
"try/catch" statement in the Main method is that the User does not get
the awful-looking message which asks the User if they wish to SEND the
error to Microsoft. It might be the very same message but it doesn't
look as bad.
Well, I guess that's a matter of opinion. If you are embarassed that a
user might see the standard Windows application error dialog, and don't
want information sent to Microsoft that might help avoid similar problems
in the future, I guess you can wrap an exception in your own dialog. You
could even design the dialog to make it look like someone else's fault if
you like.

But personally, I don't see the difference. The application shouldn't
have an unhandled exception in the first place, and changing the visual
representation of the unhandled exception doesn't seem useful to me.

Your mileage may vary.
2. I've been thinking of this issue for the last 24
hours, and I think I have an interesting solution, as least as
something to try: I'm going to create a static (global) variable (a
string array probably) and call it something like CurrMethodName. Then
at the top of most or every method, I'm going to set its value to the
name of the current method. Then I'll do the Main-level universal
Try/Catch, and display both the error message AND the value in the
string (for diagnostic purposes).
It seems to me that there are better ways to deal with that than having to
go modify each and every method in your application to set a "global"
variable. For example, the Exception class already includes a StackTrace
member that should give you all the information you need to indicate where
the exception occurred. However, if that's how you prefer to address the
issue, I can't think of a good reason to not do it that way.

Pete
Jun 8 '07 #6
Rex
Fred and Pete - Thanks alot!! I did not know about that property. You
may have saved me a bunch of code. I'll look into it, and thanks
again,
Rex
On Fri, 08 Jun 2007 20:04:03 GMT, "Fred Mellender"
<no****************@frontiernet.netwrote:
>Consult documentation on Exception.StackTrace property. You
could print this out (instead of capturing the name of the method upon entry
to each function).
"Rex" <Re**********@OneSimpleHabit.comwrote in message
news:hj********************************@4ax.com.. .
>Hi Peter and Aneesh,
Thank you both your input - they were both helpful in their own way!
Peter, a couple of points: 1. The advantage of putting a universal
"try/catch" statement in the Main method is that the User does not get
the awful-looking message which asks the User if they wish to SEND the
error to Microsoft. It might be the very same message but it doesn't
look as bad. 2. I've been thinking of this issue for the last 24
hours, and I think I have an interesting solution, as least as
something to try: I'm going to create a static (global) variable (a
string array probably) and call it something like CurrMethodName. Then
at the top of most or every method, I'm going to set its value to the
name of the current method. Then I'll do the Main-level universal
Try/Catch, and display both the error message AND the value in the
string (for diagnostic purposes). If you or anyone has further
thoughts on this, I am open! Thanks again,
Rex
On Fri, 08 Jun 2007 07:38:09 -0000, "Aneesh Pulukkul[MCSD.Net]"
<an******@gmail.comwrote:
>>>On Jun 8, 4:52 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 07 Jun 2007 14:43:34 -0700, Rex
<RexForum4...@OneSimpleHabit.com>
wrote:

1. Is it recommended to put all of the "Main" coding within a "try"
block (along with a "catch" that catches all Exceptions) so that your
application will never abnormally terminate?

I don't know what's recommended. But I wouldn't bother, unless I had
some
specific sort of cleanup-before-exit stuff I had to make sure happened,
or
if my application had some way to sensibly recover from an exception
*instead* of exiting.

After all, if you have no special cleanup to do, and all you're going to
do is catch the exception and then exit, then that's what Windows does
for
you already. :)

2. As you read the following, realize that I do NOT have a clear
overall approach for this... So much of the following describes some
questions that have initially occurred to me as I consider my design.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?

I don't think so, not in .NET. I still have methods that return boolean
results, but they do so only in what are considered normal situations.
I
would not write a method that returns a boolean, but which should in
theory never return "false" (or "true", depending on how you define the
result :) ). That seems like a waste to me, and is exactly the kind of
situation in which exceptions are useful.

After all, if your method returns a value that should always be "true",
but you require the caller to check the return value, where is the
benefit
in that? What is the caller supposed to do with an invalid return
value?
Propogate the value back to the caller? Isn't that what exceptions do
for
you already?

And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)

See above. :)

And should the error message that the User sees always
come from the called routine?

Another benefit of exceptions is that they can be specific to what went
wrong. Sometimes it is useful to use the InnerException to wrap an
exception in another exception. This would aid, for example, in having
an
exception include both the fact that there was some i/o error, as well
as
the fact that the i/o error occurred while trying to perform some
higher-level application operation (the InnerException would be the one
thrown by the file access class, like FileStream for example, while the
wrapping exception would be thrown by the higher-level application code
that was trying to do some operation).

And does this mean I would implement a
Try block in every called method???

You should only implement a try/catch block if you can do something with
the exception. It is pointless to catch an exception only to just
rethrow
it. In some cases, you may need to do some cleanup, which would be
another reason to catch the exception, but most of the time any cleanup
you need to do can be handled automatically by the "using" statement
with
objects that implement IDisposable.

I would very much appreciate
anyone who can help me sort all of this out... which brings me to...

3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?

Not off-hand, no. But I'm sure they are out there. :)

Pete

Some best practices from MSDN:
http://msdn2.microsoft.com/en-us/lib...ts(VS.71).aspx

And some fundementals:http://msdn2.microsoft.com/en-us/library/
2w8f0bss(VS.71).aspx

Again we have many links for best practices posted by developers:
http://www.codeproject.com/dotnet/ex...tpractices.asp
http://www.c-sharpcorner.com/UploadF...anagement.aspx
Jun 9 '07 #7
"Rex" <Re**********@OneSimpleHabit.comwrote in message
news:2p********************************@4ax.com...
>
Re: Looking for Tips/Writeup on overall approach to Exception
Processing
I think it would be useful for you to have a look at "Design By Contract".
Although I have reservations about it as a design approach, the concept of
contracts on which it is built is a good way of thinking about how to use
exceptions.
So here goes: Let's say most or all of my Application's methods
return a bool to indicate whether the routine successfully completed
or not. The bool will be equal to "false" ONLY if there is a logic
error or system error - never due to some invalid input from the User
and never, for example, because a User file is not found. Does it make
sense to do it this way?
Probably not. Think about what the method should do, and what conditions
have to apply for it to succeed in doing that. Document those conditions
(the "preconditions")and require the client to make sure they apply, at
least insofar as the client can. For debugging check that the client /has/
met the preconditions and throw an exception if they haven't. If it's an
exposed interface (eg, a library interface) consider leaving the check in
the the released version. Debugging or not, if the preconditions are met and
the method fails to do what it promises, raise an exception.

That's not the be-all and end-all of exception handling, but it's a good
start.
And if so, should the calling routine always
check for this "false" value on all called methods??? (which could be
alot of code!)
Which is one big advantage of exceptions.
And should the error message that the User sees always
come from the called routine?
Another big advantage of exceptions is that they can be handled at an
appropriate level. A low level method might have no idea about what it's
being used for, and so has no change of producing a message that's
meaningful to the user in the context of what they were trying to do. Let
the exception propogate up to a higher level, and the application can
account for what it was trying to achieve with the lower level call, and
what it means to the user. Then you can give an error message in the
/user's/ terms, not in the /program's/ terms (if the error looks like being
a logic error, though, consider making the exception trace available to the
user in a form that they can easily report back to you, such as an error log
file that they can email to you).

Any error message that a low-level method can generate is almost certainly
useless to a user, and will probably only serve to annoy them.
And does this mean I would implement a
Try block in every called method??? I would very much appreciate
anyone who can help me sort all of this out... which brings me to...
No. You only catch an exception if you are in a position to do something
useful with it.
3. Does anyone know of any document on the Web with some tips and/or
suggested overall approaches to Exception Processing?
This thread? ;-)
Jun 9 '07 #8
2. I've been thinking of this issue for the last 24
hours, and I think I have an interesting solution, as least as
something to try: I'm going to create a static (global) variable (a
string array probably) and call it something like CurrMethodName. Then
at the top of most or every method, I'm going to set its value to the
name of the current method. Then I'll do the Main-level universal
Try/Catch, and display both the error message AND the value in the
string (for diagnostic purposes). If you or anyone has further
thoughts on this, I am open! Thanks again,
A maintenance nightmare, and a waste of time. C# already knows where the
exception was generated. Anyway, you should handle the exception at the
first point at which you have enough information to usefully handle it. In
an event-driven architecture that is unlikely to be the "main" level, and if
you let an exception propogate to that level you've almost certainly got
your design badly wrong.
Jun 9 '07 #9
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
The application shouldn't have an unhandled exception in the first place
That's the salient point here...
--
http://www.markrae.net

Jun 9 '07 #10
A few general tips:

- Use exceptions for things that shouldn't happen, not for expected
situations such as end-of-file. (For quick ways to find the end of a binary
file see http://www.codeproject.com/cs/files/...yfileinput.asp.)

- Don't catch an exception if you're not going to handle it.

- Remember that an exception can have an InnerException.
Jun 9 '07 #11
>The application shouldn't have an unhandled exception in the first place
>
That's the salient point here...
Truly weird things ("this disk drive disappeared while I was writing on it")
will occasionally happen and can't or shouldn't be foreseen. There's a
place for unhandled exceptions, but they should be for strange events.
Jun 9 '07 #12
On Sat, 09 Jun 2007 08:56:15 -0700, Michael A. Covington
<lo**@ai.uga.edu.for.addresswrote:
Truly weird things ("this disk drive disappeared while I was writing on
it")
will occasionally happen and can't or shouldn't be foreseen.
An application should not exit because of a file i/o error.

If the boot drive disappears, then yes...there are certain things outside
an application's control. But if the boot drive disappears, the
application's failure to write to a file and subsequent exit is the least
of the user's worries (though even in that case, the exception caused by
the act of writing to the file should still be handled). And for storage
devices _generally_ disappearing or otherwise having an error, that
absolutely CAN be foreseen and should be addressed.
There's a
place for unhandled exceptions, but they should be for strange events.
By definition, an unhandled exception is one that the application didn't
handle. The application should always protect itself against exceptions
by handling them.

Pete
Jun 9 '07 #13

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Sat, 09 Jun 2007 08:56:15 -0700, Michael A. Covington
<lo**@ai.uga.edu.for.addresswrote:
>Truly weird things ("this disk drive disappeared while I was writing on
it")
will occasionally happen and can't or shouldn't be foreseen.

An application should not exit because of a file i/o error.
I agree. The application should cancel the file i/o operation and return
control to the user, if possible, or if not, at least report intelligently
what happened. I need to think of something weirder for an example.
Jun 9 '07 #14

"Michael A. Covington" <lo**@ai.uga.edu.for.addresswrote in message
news:Ol*************@TK2MSFTNGP02.phx.gbl...
>
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
>On Sat, 09 Jun 2007 08:56:15 -0700, Michael A. Covington
<lo**@ai.uga.edu.for.addresswrote:
>>Truly weird things ("this disk drive disappeared while I was writing on
it")
will occasionally happen and can't or shouldn't be foreseen.

An application should not exit because of a file i/o error.

I agree. The application should cancel the file i/o operation and return
control to the user, if possible, or if not, at least report intelligently
what happened. I need to think of something weirder for an example.
Some things are going to kill your app no matter how defensively you code.

RAM corruption, for example. If your recovery code gets corrupted, you're
totally out of luck.

Jun 9 '07 #15

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

Similar topics

22
2250
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
1
1504
by: Larry Rekow | last post by:
ve built various web apps using Frontpage and/or ASP and Access, but now I'm trying to figure a way to do the following: My friend gets parts lists in invoices (they are in an excel spreadsheet)...
7
1473
by: Jozef | last post by:
Hello, I have some archaic code that I've always used to browse the file system. Is there anything short and sweet I could use intead, without having to rely on a new reference? I've used this...
16
8465
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
1
1785
by: MD | last post by:
Hello I work in a .NET environment and I am about to create a development strategy. As part of this I am looking at implementing a testing tool to fit in with an iterative approach and NUnit...
1
3007
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
6
3833
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
6
1902
by: Lex Hider | last post by:
Hi, Apologies if this is against etiquette. I've just got my first python app up and running. It is a podcast aggregator depending on feedparser. I've really only learnt enough to get this up and...
0
6905
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...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6908
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
5331
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,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
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
2994
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
1299
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 ...
0
178
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.