473,395 Members | 1,437 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,395 software developers and data experts.

Try Catch Overkill

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
5 1457
"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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
21
by: Rob Nicholson | last post by:
Why doesn't try..catch work on my asp.net page? Try Dim n As Integer = 10 n = n / 0 Catch ex As Exception ' ignore error End Try When I single step over the n=n/0 line, it goes straight to...
8
by: CarpetMnuncher! | last post by:
================================================================= How do I use Try Catch error handling when a timer is involved? If I preform the preciduer below and I get an error I revive...
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
3
by: RipperT | last post by:
Hello, I am using VB2005. I would like to check a textbox to see if it is blank using a Try Catch block. I assumed an easy way to do that would be to perform some action on the string that can't...
23
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
5
by: Morten Snedker | last post by:
The use of Try in the Finally part - is that overkill?. I think of the code failing before opening sqlCon - that would generate an error in the Finally part. How would Finally handle that? Try...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
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...
0
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...

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.