For our codebase, i need to find all the catch statements that don’t print the stacktrace..
So a line like this;
catch (Exception e) { }
or
catch (Exception e) {
Do Something
}
or
catch (Exception e) {
}
While not including if the string “StackTrace” is included anywhere between the { }
I’ve this
catch\b\s*\(.*\)\s*\{.*\n*(?!stackTrace).*\n*\}
Which seems to be mostly working except for multiple lines..
Can anyone help?
Thanks
EDIT: Some examples of failures.. It tends to fail on this;
} catch (NameNotFoundException e) {
}
It works for this
} catch (JSONException e) {
}
I would use a regular expression to find each
catch(...)then scan downwards line-by-line, counting open/close braces until the end of the catch block. At each line of the scan using a regex to check for “StatckTrace”.