Avoiding abortion of a macro after encountering error


I’m running a plugin via an ImageJ macro and the plugin sometimes pops out error message dialogs containing a warning. The warning itself is not critical but the problem is, that the macro stops running when it encounters the error dialog. If I run the plugin from the ImageJ GUI, I can just keep clicking ok whenever the error messages pop up and the plugin runs all the way to the end just fine.

So, is there a way to stop the abortion of the macro without modifying the plugin itself? I’m aware of the IJ.redirectErrorMessages method, but it only stops the first error message from aborting the macro. If I happen to run into more than one error when the plugin is running, the macro stops.


@Kimmo_Kartasalo Can you post a short macro which illustrates the problem you are trying to avoid?

@ctrueden I had the problem with the HyperStackReg plugin https://sites.google.com/site/vedsharma/imagej-plugins-macros/hyperstackreg, which is basically the StackReg plugin with the added functionality of processing hyperstacks with additional channels. The author of the plugin was most helpful and I was already able to get rid of the error. Of course, that doesn’t really answer my question of whether there is a way to suppress errors completely for example with some kind of permanent redirection of error dialogs to the ImageJ log. So, this issue is not critical for me at the moment but it would be nice to know if there is a way around these things.

You can reproduce the error by downloading the HyperStackReg plugin https://sites.google.com/site/vedsharma/HyperStackReg_v05.class?attredirects=0&d=1 into the “Plugins” folder, opening the attached three images (any other images of your own will probably do just as well) and by running the following macro commands:

run("Images to Stack", "method=[Copy (center)] name=Stack title=[] use");
run("Stack to Hyperstack...", "order=xyczt(default) channels=3 slices=1 frames=3 display=Grayscale convert");
run("HyperStackReg v05", "transformation=Affine channel1 channel2 channel3 show");

You should get an error dialog “Warning: complex eigenvalue found; ignoring imaginary part.”. As said, the error itself is not relevant and I was able to get rid of it by not using the grayscale display mode. But if you have any thoughts on how to keep the macro running without having to interact with the GUI by clicking OK on the error dialogs, any advice might come in handy if I run into errors that cannot be avoided in the case of some other plugin in the future.

1 Like