Debug and Catch/Try

I think that I am having some problems in debug mode - 2015R3.1 Desktop on MacOS10.11.2.

Have the following code in which I am trying to determine (a) whether or not a given key is present in a dictionary, and, (b) if the key is present, what the corresponding value is. All valid values are constrained to be in the range of 0 and greater (like an array index). Code is:

       //all valid PortDict values are 0 or greater
      Try
        J = PortModule.PortDict.value(Name)
      Catch err as KeyNotFoundException
        J = -1
      End try

When debugging, it always stops at the code line following the Try statement (if Name is not already in the dictionary) and I have to tell it to resume. I could tell it NOT to break on exception, but this does not seem like it should be happening with the Try/Catch structure (unless there is no exception statement that matches the actual error). And, if I tell it not to break on exception, that will not catch other possible errors.

Am I doing something wrong?

Thanks
Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home

I think that’s the correct behavior. You can use Pragma BreakOnExceptions to prevent the break.

There is a BreakOnExceptions pragma, but for this specific code I would recommend using Dictionary.Lookup instead of Dictionary.Value and avoid exceptions altogether.

Thanks, Joe -

I missed any comments about that in the L.R.

Jim

Lookup is the better choice in this case. For others, it might be HasKey, another Dictionary function.