|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Try Catch OverkillDoes 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. "pigeonrandle" <pigeonran***@hotmail.com> wrote in message I'd say overkill. Your app should have some sort of general method of news:1162335901.463640.177890@k70g2000cwa.googlegroups.com... > Hi, > Does this bit of code represent complete overkill?! catching an exception and i think this comes into that category. Have a look at the Application.ThreadException event. Michael "pigeonrandle" <pigeonran***@hotmail.com> wrote in message Please don't multipost.news:1162335901.463640.177890@k70g2000cwa.googlegroups.com... > Hi, > Does this bit of code represent complete overkill?! 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: Show quoteHide quote > "pigeonrandle" <pigeonran***@hotmail.com> wrote in message > news:1162335901.463640.177890@k70g2000cwa.googlegroups.com... > > Hi, > > Does this bit of code represent complete overkill?! > > Please don't multipost. pigeonrandle wrote:
> Does this bit of code represent complete overkill?! The only thing that you could usefully recover from is the Nodes.Add, > Try > Dim tn as new TreeNode() > tv.Nodes.Add(tn) which means that you won't have anything to remove, so why bother? > Catch ee As Exception 'something weird has happened Not sure if this even works - Object references should be compared using > Try > if (tn.TreeView <> Null) tn.Remove() the Is operator; I've not come acorss "Null" in Visual Basic. > if this situation arises then someone has probably poured a cup of I've not [yet] seen a CaffeinatedBeverageSpillageException - but there's > 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? a /lot/ of new stuff in VB'2005... ;-) Regards, Phill W. Phill,
Amusing. Have you looked in the System.Application.User.Stupid namespace? James. Phill W. wrote: Show quoteHide quote > 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. |
|||||||||||||||||||||||