Home All Groups Group Topic Archive Search About
Author
31 Oct 2006 11:05 PM
pigeonrandle
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.

Author
31 Oct 2006 11:26 PM
Michael C
"pigeonrandle" <pigeonran***@hotmail.com> wrote in message
news:1162335901.463640.177890@k70g2000cwa.googlegroups.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
Author
1 Nov 2006 12:08 AM
Michael C
"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.
Author
1 Nov 2006 12:41 AM
pigeonrandle
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.
Author
1 Nov 2006 2:41 PM
Phill W.
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.
Author
2 Nov 2006 12:53 PM
pigeonrandle
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.