CATIA Composer Minimal Distance

I'm using CATIA Composer R2022 API to perform some automation and in some steps of the process I need to perform measurements, more specifically get the minimum distance between two objects. I can use the "Minimal Distance" command (CrRibbonCommand.crRCmdMinimalDistance), select both objects, and based on the measurement created after command is executed it would be possible to collect minimal distance value. The problem is that when objects are intersecting each other, there's is a message box displayed (see attached image), which will freeze application and not continue performing measurements. Is there any workaround on that? Can composer just return a 0mm dummy dimension and not a message box (or either just don't create the dimesion)?