By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Try Catch Overkill

P: n/a
Hi,
Does this bit of code represent complete overkill?!

Try

'create a treenode
Dim tn as new TreeNode()
'add it to a treeview
tv.Nodes.Add(tn)
'do some other stuff

Catch ee As Exception 'something weird has happened

Try

'try to remove the treenode from the treeview
if (tn.TreeView <Null) tn.Remove()

Catch ee As Exception 'now things have got really dire

MessageBox.Show("Would a function like TreeNode.Remove() ever cause

a random exception that i should worry about?")

End Try

End Try

What i basically mean is ... if this situation arises then someone has
probably poured a cup of coffee into the computer so i won't have to
worry about my software/data being 'recoverable', or will this sort of
*hilarious* thing never happen?

Explanations, musings and criticism all welcome,
James Randle.

Oct 31 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"pigeonrandle" <pi**********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi,
Does this bit of code represent complete overkill?!
I'd say overkill. Your app should have some sort of general method of
catching an exception and i think this comes into that category. Have a
look at the Application.ThreadException event.

Michael
Oct 31 '06 #2

P: n/a
"pigeonrandle" <pi**********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi,
Does this bit of code represent complete overkill?!
Please don't multipost.

Nov 1 '06 #3

P: n/a
I did go to the trouble of converting the code to VB. Besides, it's
nice to get different people's opinions.

James.

Michael C wrote:
"pigeonrandle" <pi**********@hotmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi,
Does this bit of code represent complete overkill?!

Please don't multipost.
Nov 1 '06 #4

P: n/a
pigeonrandle wrote:
Does this bit of code represent complete overkill?!
Try
Dim tn as new TreeNode()
tv.Nodes.Add(tn)
The only thing that you could usefully recover from is the Nodes.Add,
which means that you won't have anything to remove, so why bother?
Catch ee As Exception 'something weird has happened
Try
if (tn.TreeView <Null) tn.Remove()
Not sure if this even works - Object references should be compared using
the Is operator; I've not come acorss "Null" in Visual Basic.
if this situation arises then someone has probably poured a cup of
coffee into the computer so i won't have to worry about my software/data
being 'recoverable', or will this sort of *hilarious* thing never happen?
I've not [yet] seen a CaffeinatedBeverageSpillageException - but there's
a /lot/ of new stuff in VB'2005... ;-)

Regards,
Phill W.
Nov 1 '06 #5

P: n/a
Phill,
Amusing. Have you looked in the System.Application.User.Stupid
namespace?

James.

Phill W. wrote:
pigeonrandle wrote:
Does this bit of code represent complete overkill?!
Try
Dim tn as new TreeNode()
tv.Nodes.Add(tn)

The only thing that you could usefully recover from is the Nodes.Add,
which means that you won't have anything to remove, so why bother?
Catch ee As Exception 'something weird has happened
Try
if (tn.TreeView <Null) tn.Remove()

Not sure if this even works - Object references should be compared using
the Is operator; I've not come acorss "Null" in Visual Basic.
if this situation arises then someone has probably poured a cup of
coffee into the computer so i won't have to worry about my software/data
being 'recoverable', or will this sort of *hilarious* thing never happen?

I've not [yet] seen a CaffeinatedBeverageSpillageException - but there's
a /lot/ of new stuff in VB'2005... ;-)

Regards,
Phill W.
Nov 2 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.