Question Weird Null Exception

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Hey everyone. I have a program which does some basic proxy testing using multiple threads. Each proxy is put into the queue and then pulled to be tested. For some reason I occasionally get a "NullReference Exception" was unhandled error. I've tried doing a number of things with the code (IsNot Nothing..etc) but it still shows up. You can see the screenshot below and what the last changes I did were.

error1.jpg error2.jpg


Any ideas why this code (or even something like If Queue(0).url isNot Nothing then..) wouldn't fix the issue of this null exception?
 
There's no point checking whether `Queue(0).Url` is Nothing. That's like asking whether your brother has a dog when you don't have a brother. Look at the Autos window. It is telling you that `Queue(0)` is Nothing. There's no item there to even have a Url in the first place.

So, you could test whether `Queue(0)` is Nothing but prevention is better than cure, so the appropriate course of action is to not add Nothing to the queue in the first place. So, go back to where you're adding items and make sure that you only add an item if there's an object to add.
 
Back
Top