Friday, September 7, 2007

Using Regular Expressions to locate code that buries exceptions

Ok, Its a similar story as my last post. Sometimes developers catch exceptions and dont do anything with them. This makes it especially hard to detect when things dont work because there are no errors being reported!

This is my attempt at locating empty catch blocks using a regular expression

catch[\n\r\s]*\([\n\r\s]*(final[\n\r\s]*)?\S+[\n\r\s]*\S+[\n\r\s]*\)[\n\r\s]*\{[\r\n\s\w]*(?!throw)[\r\n\s\w]*\}