Click here to Skip to main content
15,890,897 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
Generalso this is a cool thing - more gplex stuff Pin
honey the codewitch22-Dec-19 16:33
mvahoney the codewitch22-Dec-19 16:33 
GeneralRe: so this is a cool thing - more gplex stuff Pin
PIEBALDconsult22-Dec-19 16:56
mvePIEBALDconsult22-Dec-19 16:56 
GeneralRe: so this is a cool thing - more gplex stuff Pin
honey the codewitch22-Dec-19 16:57
mvahoney the codewitch22-Dec-19 16:57 
GeneralRe: so this is a cool thing - more gplex stuff Pin
BillWoodruff23-Dec-19 3:01
professionalBillWoodruff23-Dec-19 3:01 
GeneralHoliday Season Fun Activity ... Not... Pin
virang_2122-Dec-19 14:55
virang_2122-Dec-19 14:55 
GeneralRe: Holiday Season Fun Activity ... Not... Pin
PIEBALDconsult22-Dec-19 15:37
mvePIEBALDconsult22-Dec-19 15:37 
GeneralRe: Holiday Season Fun Activity ... Not... Pin
Rajesh R Subramanian22-Dec-19 16:08
professionalRajesh R Subramanian22-Dec-19 16:08 
AnswerRe: Holiday Season Fun Activity ... Not... Pin
Rajesh R Subramanian22-Dec-19 16:07
professionalRajesh R Subramanian22-Dec-19 16:07 
virang_21 wrote:
Try {
// Number of code lines
}
Catch (Exception exception){
// Nothing here. Exception is swallowed.
}

Assuming that the code not wildly different than this, you could start with a simple regex replace with a blank string (PHP style, just use notepad++):
Try.*?Catch[^,;]*?\}

Update: I greatly simplified the regex ^-^, and also fixed a bug (the previous regex will match and erase any catch block that starts with a comment, but this one won't).

What does it do?
  1. If a catch block contains at least one semi-colon, then it's considered as a catch block with some valid code. Therefore, the entire try-catch is left alone.
  2. If a catch block does not contain a semi-colon, the catch is erased, along with the try block that preceeds it (regardless of what's within the try).

Note: The regex will replace EVERY invalid try-catch block depending on the path and file extension selected in your replace in files dialog, so backing up your code beforehand might be a good idea!

It should be fairly simple to modify to suit your needs if there's any difference.

It replaced everything with an empty string except for the last block in my test cases:
Try {
do stuff
more stuff
blah
}
Catch (Exception exception){
// Nothing here. Exception is swallowed.
}

Try {

// Number of code lines
// Number of code lines
/*
frigging multi-line comment
spanning over many lines

*/
// Number of code lines
}
Catch (Exception exception){

// Nothing here. Exception is swallowed.
}

Try {
// Number of code lines
}
Catch (Exception exception){
// Nothing here. Exception is swallowed.
// blah
}

Try {
// Number of code lines
}
Catch (Exception exception){
//blah
	int d = 3;
}


modified 22-Dec-19 22:41pm.

GeneralCoding as necromancy Pin
honey the codewitch22-Dec-19 9:48
mvahoney the codewitch22-Dec-19 9:48 
GeneralRe: Coding as necromancy Pin
Matthew Dennis22-Dec-19 9:55
sysadminMatthew Dennis22-Dec-19 9:55 
GeneralRe: Coding as necromancy Pin
honey the codewitch22-Dec-19 9:57
mvahoney the codewitch22-Dec-19 9:57 
GeneralRe: Coding as necromancy Pin
Jörgen Andersson22-Dec-19 10:36
professionalJörgen Andersson22-Dec-19 10:36 
GeneralRe: Coding as necromancy Pin
honey the codewitch22-Dec-19 10:37
mvahoney the codewitch22-Dec-19 10:37 
GeneralRe: Coding as necromancy Pin
Jörgen Andersson22-Dec-19 10:54
professionalJörgen Andersson22-Dec-19 10:54 
GeneralRe: Coding as necromancy Pin
honey the codewitch22-Dec-19 10:55
mvahoney the codewitch22-Dec-19 10:55 
GeneralRe: Coding as necromancy Pin
Jörgen Andersson22-Dec-19 11:13
professionalJörgen Andersson22-Dec-19 11:13 
GeneralRe: Coding as necromancy Pin
honey the codewitch22-Dec-19 11:16
mvahoney the codewitch22-Dec-19 11:16 
GeneralHappy Hanukkah too... Pin
Kornfeld Eliyahu Peter22-Dec-19 9:28
professionalKornfeld Eliyahu Peter22-Dec-19 9:28 
GeneralRe: Happy Hanukkah too... Pin
Ron Anders22-Dec-19 14:49
Ron Anders22-Dec-19 14:49 
GeneralRe: Happy Hanukkah too... Pin
CHill6023-Dec-19 1:00
mveCHill6023-Dec-19 1:00 
GeneralHappy Hollandaise! Pin
Majerus22-Dec-19 8:14
Majerus22-Dec-19 8:14 
GeneralIs this the original rock music? Pin
Daniel Pfeffer22-Dec-19 7:23
professionalDaniel Pfeffer22-Dec-19 7:23 
GeneralRe: Is this the original rock music? Pin
Ravi Bhavnani22-Dec-19 7:28
professionalRavi Bhavnani22-Dec-19 7:28 
Generalhow to restore old sources with Windows characters Pin
Erhy22-Dec-19 5:50
Erhy22-Dec-19 5:50 
GeneralRe: how to restore old sources with Windows characters Pin
Jörgen Andersson22-Dec-19 5:54
professionalJörgen Andersson22-Dec-19 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.