Sidebar

How to use try catch block in script ?

0 votes
356 views
asked Apr 30, 2019 by (330 points)
please gimme one use case of try catch block in QIE.

1 Answer

0 votes

One example is if you are expecting an HL7 message but can get other data that you do not want to process. By default if you try to parse this as an HL7 string it would error "Unknown Segment" and put it in the error queue. However if you want it to just discard you would use a try/catch.

//try to parse a string as hl7 that is not an hl7 message. This will throw an error "Unknown segment: 'Thi'".
//We are going to catch the error and just send a debug message.
//Then we will discard the message so that is not in the error queue.
try {
   var hl7 = qie.parseHL7String('This is not an hl7 message');
} catch (err) {
   if (StringUtils.containsIgnoreCase(err, 'Unknown segment:')) {
      qie.debug('invalid hl7 was passed to the parseHl7String');
      message.discard();
   }
}

answered May 1, 2019 by brandon-w-8204 (33,330 points)
...