How can I skip this error: Java.lang.ArrayIndexOutOfBoundsException 0?

I am doing a loop in macro imagej and when an image is fully black I receive this error: Java.lang.ArrayIndexOutOfBoundsException 0
Is there any way to go to the next image if this error encounters instead of giving error and stop running?
I need sth like if conditional if error, go to the next image but dont know how to shape it in imagej.

Hi,
there is no exception handling in the macro language. You need to test if the condition that leads to the error is given yourself, something like:

getStatistics(area, mean, min, max, std, histogram);
if(max==0) {
	print("the image is empty");
	continue;
} else {
	processCurrentImage();
}

Of course the condition might need to be adapted to what you mean by “fully black”.

Best regards,
Volker

1 Like

Thanks Volker for the respond. I think this error means that not area, min, max,.. has be calculated. so if max==o does not apply in this case. I know in other languages like matlab that there is try/catch syntax and I am looking for sth similar in imagej that can catch the error and avoid breaking the code.

Hi,
as I said, there is no exception handling in the macro language, i.e. no "try/catch"-mechanism. You can switch to a scripting language where exception handling exists. If you want to stay with ij-macro, you need to find out where the error comes from and avoid it.
Best regards,
Volker

This is probably a bug in the macro language. Please post a minimal test macro that reproduces the bug. This is needed to fix the problem.