Yeah, I saw that later. Because this is Jython, I don't think you should make assumptions about the cheapness of exceptions (which are Java exceptions under the hood). But without measuring it, I guess this is as good as any other approach.