C#: Find all empty catch blocks
Use use the global find dialog, turn on regular expressions and then search for:
catch:b*\([^)]*\):b*\{:b*\}
Expanded the accepted answer to satisfy all the conditions described below. Updated for Visual Studio 2017/2019, works for both C# and C++.
Use the find dialog (CTRL+SHIFT+F), turn on regular expressions and search for:
^(?!\/\/|\/\*).*catch\s*(?:\([^)]*\))*\s*\{\s*(?:(?:\/\/|\/\*).*(\*\/)?\s*)*\}
Matches:
catch {}
catch{}
catch{
}
catch
{}
catch () {}
catch (...) {}
catch (int x) {}
catch (Exception x) {}
catch (Exception ex){
}
catch(...){
}
} catch (...){
/**/
}
} catch (...){
/**/
///
}
} catch (...){
//
//
/**/
}
catch (...)
{}
catch(...) { //single line
}
catch(...) {
//single line}
catch(...) {
//single line
}
catch(...) { /*multiline*/
}
catch(...) {
/*multiline*/}
catch(...) {
/*multiline*/
}
catch (...){ // int i = 0; }
Does not match:
// catch () {}
/* catch () {} */
catch (...){ int i = 0;}
catch (...){
int i = 0;}
catch (...){int i = 0;
}
catch (...){
// Comment
int i = 0;}
catch (...){ int i = 0; // Comment}