Errors Not Trapping In Protocol Functions


Recommended Posts

I have the following code in an internal function in a protocol.  I get errors thrown saying there's an unknown channel or function, from the first two return() lines in the try() block (on different calls).  Not only does the error itself baffle me, but I can't imagine why the try() isn't trapping the error  and why the catch() isn't getting executed.  Any thoughts?

function decode(arrByteData, iFileType, bUnsigned)
   if(IsEmpty(arrByteData))
      return null
      endif
   if(argc < 3)
      private bUnsigned = 0
      endif
   private iByteSize = SizeOf[IFileType]
try()
   if(iFileType == 0x8a)
      return(To.Float(From.HexString(To.HexString(arrByteData), ibyteSize)))
   else
      if(bUnsigned == 0)
         return(To.Word(From.HexString(To.HexString(arrByteData), ibyteSize)))
      else
         return(To.uWord(From.HexString(To.HexString(arrByteData), ibyteSize)))
         endif
      endif
catch()
   ?iByteSize
   return null
   endcatch
Link to comment
Share on other sites

First, its just try, not try() which may be why its not processing the catch.  Second, I'm guessing that ifileType is past the end of the sizeof array, which makes iBytesize empty.  I would add ? statements to help debug since you can't step through the protocol code.

Link to comment
Share on other sites

If iFileType is past the end of SizeOf[], then why doesn't this line throw a fault?

private iByteSize = SizeOf[IFileType]

Plus, I don't think it's possible for it to be > than NumRows(SizeOf), but I'll check and see if I can think of any way.  Thanks for the heads up on try vs. try().

Link to comment
Share on other sites

Alright, iByteSize was fine; turns out that the problem was that sometimes I'd get a partial response fron the device with  a number of bytes not divisible by the 2 or 4 byte size of target data type, so it would fail on the conversion step.  The stuff you run into when you switch from bench testing to real-world applications!  (BTW, the conversion kind of grew organically, which is why it has the if/else if/ else structure.  Looking at the end product, it looks like a case switch would be cleaner.)

 

I added a check on the returned byte count before sending the data to Decode().

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.