带有“分析粒子"的dm-script捕获错误; [英] dm-script catch error with "Analyze Particles"

查看:100
本文介绍了带有“分析粒子"的dm-script捕获错误;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样做

ChooseMenuItem("Analysis", "Particles", "Analyze Particles") 

我有时会收到无效索引"错误窗口.有没有办法捕获该错误? 为此,

I sometime get "Invalid index" error window. Is there a way to catch that error? Doing this,

try {
    ChooseMenuItem( "Analysis", "Particles", "Analyze Particles" )
}
catch {
    okdialog("error")
}

没有捕获到错误.菜单操作分析粒子"完成后,无效索引"错误很可能是错误.谁能指出如何捕获此错误?并且找出此错误的根源是一个很大的优点.我正在使用GMS 1.84.

does not catch the error. The "Invalid index" error is likely an error after the menu action "Analyze Particles" is done. Can anyone point out on how to catch this error? And finding out the origin of this error is a great plus. I am using GMS 1.84.

推荐答案

我认为您遇到的问题是粒子分析正在(至少部分)在单独的后台线程上运行.

在这种情况下,我认为没有办法直接捕获这些异常.

I think the problem you're encountering is that the Particle-Analysis is running (at least partly) on a separate background-thread.

I don't believe there is a way to directly catch these exceptions in this case.

我不再使用GMS 1.84,但是我确实在GMS 3.2上进行了尝试,您可能还想做一些事情,以更好地了解正在发生的事情.

I don't use GMS 1.84 anymore, but I did try things on GMS 3.2 which you might also want to do to understand better what's going on.

首先,您的Try/Catch循环是可以的,但是如果您没有在catch中放置"break",那么一旦保留catch部分,异常就会被提升到系统中,即您经常想做:

First, your Try/Catch loop is OK, but if you don't put a 'break' in the catch, then the exception will nevertheless be elevated to the system, once the catch-section is left, i.e. you often want to do:

Try{ 
    ... }
Catch{
    ...
    break
}
...


要测试脚本如何处理来自调用方法的异常,我首先编写了一个小脚本并将其安装"为菜单命令,一次有背景线程,一次没有后台线程.我通过 Custom 菜单中的文件菜单分别使用命令名称​​ BT nBT 来安装它们:


To test how scripting behaves on exceptions from a called method, I first wrote a little script and 'installed' it as menu command, once with and once without background-threading. I installed them via the File-menu in the Custom menu with command names BT and nBT, respectively:

// $BACKGROUND$
Result( "\nStart and wait" )
number i = 0
while( i < 100 ){
    i++
    sleep(0.05)
    if ( ShiftDown() ) break
    if ( OptionDown() ) Throw("Broken")
    Result( "." )
}
Result("\nDone and exit.")

Result( "\nStart and wait" )
number i = 0
while( i < 100 ){
    i++
    sleep(0.05)
    if ( ShiftDown() ) break
    if ( OptionDown() ) Throw("Broken")
    Result( "." )
}
Result("\nDone and exit.")

然后我使用'ChooseMenuItem()'在以下脚本中进行测试:

Then I used the 'ChooseMenuItem()' to do the testing in the following script:

string name = TwoButtonDialog("Background threaded?", "yes", "no" ) ? "BT" : "nBT"
number success = 0
Try{
    Result( "\n Calling: " + name )
    success = ChooseMenuItem("Custom","",name)
}
catch
{
    Result("\n Caught exception." )
    break
}
result("\n Success: " + success )

使用此组合进行测试(并使用ALT键在例程中引发异常),我可以验证命令的行为符合预期:

Testing with this combination (and using the ALT key to throw an exception in the routine) I could verify that the commands behave as should be expected:

  • 如果在主线程上启动了由ChooseMenuItem命令启动的例程,则该调用的执行会阻塞"主脚本,直到完成为止-在结尾处,或引发异常时.主脚本正确捕获异常并打印结果.
  • 如果ChooseMenuItem命令启动的例程在单独的(后台)线程上启动,则主脚本会立即继续. ChooseMenuItem立即成功返回(如果它可以启动命令),并且退出Try/Catch循环.被调用例程在后台线程上引发的任何异常将不再被捕获.
  • If the routine started by the ChooseMenuItem command is launched on the main-thread, then the execution of that call 'blocks' the main script until it is completed - either at its end, or when it throws and exception. The main script correctly catches exceptions and prints the result.
  • If the routine started by the ChooseMenuItem command is launched on a separate (background) thread, then the main-script continues immediately. ChooseMenuItem returns successfully at once (if it could launch the command), and the Try/Catch loop is exited. Any exception thrown by the called routine on the background thread will not be caught anymore.


关于错误的根源:无效索引"消息指向被主脚本删除(或保留在作用域中)的某个对象,该对象预期被调用的背景存在(或不再存在)常规.这可以是图像或imageDocument,也可以是图像或imageDisplay上任何对象(ROI,蒙版...)的显示.

As for the origin of the error: The "Invalid index" message points to some object being removed (or kept in scope) by the main-script which is expected to be there (or no longer there) by the called background routine. This could be an image or imageDocument or the display of an image or any object (ROI, mask...) on an imageDisplay.

我怀疑您的主脚本正在执行诸如关闭曾经使用过的图像之类的事情?如果分析"是在单独的线程上,则您的主脚本可能太快或太慢,导致事情不同步.您可能需要在主脚本中添加人为的停顿(sleep())和更复杂的跟踪图像的系统(使用 image-IDs ),以避免此类情况.

I suspect your main script is doing things like closing images once used? If the "analysis" is on a separate thread, your main script might be too fast or too slow and get things out of sync. You might need to add artifical pauses (sleep()) and a more sophisticated system of keeping track of images ( using the image-IDs ) in the main script to avoid such things.

使用ChooseMenuItem()是一种变通的hack解决方案,因此,针对您的问题的任何防止bug的解决方案也可能都是需要某种丑陋"创意的代码hack.

Using ChooseMenuItem() is a workaround hack solution, so any bug-preventing solution for your problem is likely also a code-hack with some ugly 'creativeness' needed.

这篇关于带有“分析粒子"的dm-script捕获错误;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆