Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Holiday Season Fun Activity ... Not...

Holiday Season Fun Activity ... Not...

Scheduled Pinned Locked Moved The Lounge
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    virang_21
    wrote on last edited by
    #1

    Going through 400 code files and finding empty catch blocks and fixing them .... Try { // Number of code lines } Catch (Exception exception){ // Nothing here. Exception is swallowed. } Highly paid consultants probably enjoying a holiday season somewhere...:mad:

    Zen and the art of software maintenance : rm -rf * Maths is like love : a simple idea but it can get complicated.

    P R 2 Replies Last reply
    0
    • V virang_21

      Going through 400 code files and finding empty catch blocks and fixing them .... Try { // Number of code lines } Catch (Exception exception){ // Nothing here. Exception is swallowed. } Highly paid consultants probably enjoying a holiday season somewhere...:mad:

      Zen and the art of software maintenance : rm -rf * Maths is like love : a simple idea but it can get complicated.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Regular Expressions ;P

      R 1 Reply Last reply
      0
      • V virang_21

        Going through 400 code files and finding empty catch blocks and fixing them .... Try { // Number of code lines } Catch (Exception exception){ // Nothing here. Exception is swallowed. } Highly paid consultants probably enjoying a holiday season somewhere...:mad:

        Zen and the art of software maintenance : rm -rf * Maths is like love : a simple idea but it can get complicated.

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        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;
        }

        1 Reply Last reply
        0
        • P PIEBALDconsult

          Regular Expressions ;P

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Ha, great minds and all. :-) OTOH, fools seldom differ either. :omg:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups