Results 1 to 25 of 25

Thread: [RESOLVED] Constructors and exceptions

Threaded View

  1. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Constructors and exceptions

    Putting the MyBase.New is a very good practice. Suppose the base class initializes some variable to some value which the derived class constructor then makes use of. Until MyBase.New has executed, the base class is not initialized, so the derived class dare not use any part of the base class. That's dangerous practice.

    By the way, when it comes to the first part, I think you should always have a test app for this kind of situation. All you would need to do is come up with some dummy class that has nothing in it but a constructor with a line that will certainly throw an exception. You can then create a dictionary keyed on whatever you want (probably an Integer), and try the code you have to see what is happening. That's probably what dunfiddlin did. You could step through the addition of the item to the dictionary and see what is in the dictionary before and after the attempted addition. I'd bet that most people on here have some form of test app to try out things they aren't quite sure about.

    Also, the maxsize sounds like something from List(of T), which either has, or had, some property like that. It wasn't a limit, though, it was a seldom used property that gave you some information about how the collection was managing things. I wouldn't have been surprised if Dictionary had the same thing, though perhaps the Dictionary manages memory differently than the List (of T) does.
    Last edited by Shaggy Hiker; Jul 23rd, 2013 at 09:47 PM.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width