Exceptions in Predicates

Today, I finished going through the simple mistakes that Bill had found in my thesis. There still are a lot of comments to address; he really gave me a lot of feedback. Thanks, Bill!

One comment that was particularly important was the question: “What happens if an exception is thrown in a predicate?” I never thought of that. Up until now, the exception would unwind the stack and terminate the program. That’s probably not what the programmer wants, though; generally, I designed the predicate checks to be as invisible as possible.

An exception in a predicate should be treated as an error, but it’s a particular kind of error: An error in the code that is there to check the behavior of the program! What I did this afternoon was add a try { ... } catch(Throwable t) { ... } block around every predicate check. If an exception is thrown, then a different log method is invoked. The exception is noted but consumed, and program execution continues.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in Concurrent Unit Testing, MS Thesis. Bookmark the permalink.

Leave a Reply