Results 1 to 5 of 5

Thread: [RESOLVED...ISH] Constructors Swallowing Exceptions...sort of.

Threaded View

  1. #1

    Thread Starter
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Resolved [RESOLVED...ISH] Constructors Swallowing Exceptions...sort of.

    I'm beginning to think that my version of VS has gone utterly mad. See the other threads I've started over the last few days. However, all of those ended up having reasonable explanations. This one does not.

    Take the line of code below, which will mean nothing. It is a bug, because I called the wrong method from an interface (IRUBOReadOnly). I created that interface, along with the only classes that implement it, so I know it pretty well.

    Code:
    Me.lSumDestination.Text = mERaiser.IRUBOReadOnly.GetHatcheries(mConfig.DestinationHatcheryID)
    Anybody who read that last thing, it wasn't the real question. I screwed something up. I've known about this, but it has never tripped me up before. The method shown doesn't take any arguments. It can be written as GetHatcheries or as GetHatcheries(). Both will work fine, and will do what I expect. However, that method will return a Dictionary(of GUID, string). Therefore, I was surprised that I could seem to pass it an argument, but what's happening is that it is referencing the GUID I supplied in the dictionary that was returned from GetHatcheries, and returning the string associated with that GUID...which was nothing, because the GUID supplied wasn't in the dictionary...because the line was a mistake to begin with. I haven't been tripped up by that before, but was this time. That was fun, but it side tracked me from the question I wanted to ask.

    The line, as written should have thrown an exception. It is found in the constructor for a form that is part of a plugin. Exceptions thrown by plugins will get handled, or noted, but I couldn't get this to do much of anything. It didn't log an error, it didn't crash the program, it didn't put up any message, the form simply failed...and things went along as if I hadn't done anything.

    I realize that an exception thrown in a constructor is a pretty weird animal that can have some bad consequences, but doing nothing was not what I expected. What IS the correct behavior for when a form constructor throws an exception?
    Last edited by Shaggy Hiker; Apr 11th, 2022 at 02:49 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