|
-
Apr 11th, 2022, 02:10 PM
#1
[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
 
-
Apr 11th, 2022, 02:20 PM
#2
Re: Constructors Swallowing Exceptions...sort of.
Presumably the GUID is being interpreted as an index to the Dictionary (or perhaps as a parameter to the default method of a dictionary).
If that is the case, I would expect the item returned by it to either be a String, or something that can be converted to a String.
-
Apr 11th, 2022, 02:27 PM
#3
Re: Constructors Swallowing Exceptions...sort of.
I thought somebody might have read that. You are right. I had forgotten that a method doesn't need the () at the end if it takes no arguments, so when I added (someGUID), it indexed into the dictionary and returned the string. I had worked that out, so changed the question back to the original issue: The line should have thrown an exception (it's not the write method call, for one thing, that's a typo), but the result was a very quiet exit.
My usual boring signature: Nothing
 
-
Apr 11th, 2022, 02:37 PM
#4
Re: Constructors Swallowing Exceptions...sort of.
This may be a very peculiar edge case. The code that is throwing the exception is in a plugin. That means that the method that is showing the form is in an object that was created from a dynamically loaded dll. Normally, exceptions thrown by a plugin behave as any other exception would. If the exception is not handled by the plugin, and isn't handled anywhere else...it seems to just vanish.
My usual boring signature: Nothing
 
-
Apr 11th, 2022, 02:49 PM
#5
Re: Constructors Swallowing Exceptions...sort of.
Turns out that the behavior is not consistent. I was trying to study this further and the behavior changed. Instead of quietly swallowing the error and continuing, it started crashing the program. That's what I had expected it to do. So, I guess whatever caused it to swallow the exception was a temporary thing that is now gone, and behavior has returned to what I expected.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|