Find and Replace Try/Catch Using Search Structurally
I feel like Search Structurally is a really powerful tool that I don't understand how to use.
I am trying to find instances where an Exception has been caught and the Logger has eaten the stacktrace - i.e. the Exception is not passed to the logger.
So far I have this:
try {
$TryStatement$;
} catch($ExceptionType$ $Exception$) {
$logger$;
}
Where $logger$; is a custom variable defined as: Log.error.*\"\)
This doesn't quite seem like the right way to do it but I can't follow the help.
Look at the help for this:
Search in comments and/or string literals
Consider one wants to find comments or literal containing 'foo'. Search template would be like $SomethingWeWantToFind$
or "$SomethingWeWantToFind$"
. In case one wants to find comments/string containing some particular words (say, foo as a word), this should be specified as a text constraint.
What??
What is the difference between the quoted version and the unquoted version?
How does $SomethingWeWantToFind$
help us find 'foo'?
Lots of clicking of buttons made me realise that "text constraint" is something specified when you click "Edit Variables" but it isn't mentioned here.
This would be a lot clearer if you had lots more screenshots and step by step examples with screenshots of actual code that is found instead of random words like 'foo'.
Please sign in to leave a comment.
You probably want to use a query something like this:
$TryStatement$ min: 1 max: unlimited
Unfortunately this will only find try statements with one catch block, this is a limitation of Structural Search.
If it still doesn't work, please provide a concrete sample of the code you are trying to find.
Bas
That still didn't work. I put .*\"\) in the $string variable.
Sample code
Here is a slightly different version with an example
Sample code:
Test search:
That initially found nothing until I checked all the variables and found that my regex from $string had popped into $TryStatement
There needs to be some highlighting to indicate what are built in variables and what are user variables.
There should also be a list of what all the built in variables are and what they mean in the help files.
When a user variable is missing a constraint it should be highlighted as an error with a popup balloon saying "Click Edit variables to define this variable or add constraints" or something along those line.