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. Other Discussions
  3. The Weird and The Wonderful
  4. Happy debugging!

Happy debugging!

Scheduled Pinned Locked Moved The Weird and The Wonderful
debugginghelpcsharpjavaphp
40 Posts 26 Posters 2 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.
  • A Andrei Straut

    While debugging some problems in an automated console application I ran into this:

    try {
    //some code
    } catch(Exception e) {}

    I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

    class TheClass {

    /\*Overriden the GetType class method so that it returns a different class name than it should,
    it no longer returns the name of the class it's in\*/
    private string GetType() {
        return "ISyncService";
    }
    
    private int methodThatThrewError() {
        //some code
            
        try {
            //some other code
        } catch(Exception e) {
            /\*We log exceptions by class name, method where it occurred 
            and exception message, plus optionally stack trace\*/
            Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
    
            /\*Also make sure we're always successful\*/
            return successCode;
        }
            
        return successCode;
    }
    

    }

    Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

    Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

    B Offline
    B Offline
    Brisingr Aerowing
    wrote on last edited by
    #2

    That's just evil. And I like it. +5!

    I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

    1 Reply Last reply
    0
    • A Andrei Straut

      While debugging some problems in an automated console application I ran into this:

      try {
      //some code
      } catch(Exception e) {}

      I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

      class TheClass {

      /\*Overriden the GetType class method so that it returns a different class name than it should,
      it no longer returns the name of the class it's in\*/
      private string GetType() {
          return "ISyncService";
      }
      
      private int methodThatThrewError() {
          //some code
              
          try {
              //some other code
          } catch(Exception e) {
              /\*We log exceptions by class name, method where it occurred 
              and exception message, plus optionally stack trace\*/
              Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
      
              /\*Also make sure we're always successful\*/
              return successCode;
          }
              
          return successCode;
      }
      

      }

      Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

      Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

      P Offline
      P Offline
      Patrice STOESSEL
      wrote on last edited by
      #3

      Why don't you speak to this colleague ? Until today, to speak is the best way to explain your point, and to be understood. You might even learn something doing so ... To play more stupid than the stupid is a sure way to failure, for both you and him.

      gzo

      A B 2 Replies Last reply
      0
      • P Patrice STOESSEL

        Why don't you speak to this colleague ? Until today, to speak is the best way to explain your point, and to be understood. You might even learn something doing so ... To play more stupid than the stupid is a sure way to failure, for both you and him.

        gzo

        A Offline
        A Offline
        Andrei Straut
        wrote on last edited by
        #4

        I did, and nothing changed. Although this colleague is a friend, and one of my best actually, he did nothing on this despite my repeated requests.

        Patrice STOESSEL wrote:

        To play more stupid than the stupid is a sure way to failure, for both you and him.

        I'm not sure whether to take this as offensive or not.

        Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

        S 1 Reply Last reply
        0
        • A Andrei Straut

          While debugging some problems in an automated console application I ran into this:

          try {
          //some code
          } catch(Exception e) {}

          I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

          class TheClass {

          /\*Overriden the GetType class method so that it returns a different class name than it should,
          it no longer returns the name of the class it's in\*/
          private string GetType() {
              return "ISyncService";
          }
          
          private int methodThatThrewError() {
              //some code
                  
              try {
                  //some other code
              } catch(Exception e) {
                  /\*We log exceptions by class name, method where it occurred 
                  and exception message, plus optionally stack trace\*/
                  Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
          
                  /\*Also make sure we're always successful\*/
                  return successCode;
              }
                  
              return successCode;
          }
          

          }

          Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

          Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

          V Offline
          V Offline
          VallarasuS
          wrote on last edited by
          #5

          Together as a team you failed! so your employer! ...

          Regards Vallarasu S | BreakingDotNet.blogspot.com

          1 Reply Last reply
          0
          • A Andrei Straut

            I did, and nothing changed. Although this colleague is a friend, and one of my best actually, he did nothing on this despite my repeated requests.

            Patrice STOESSEL wrote:

            To play more stupid than the stupid is a sure way to failure, for both you and him.

            I'm not sure whether to take this as offensive or not.

            Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

            S Offline
            S Offline
            Sentenryu
            wrote on last edited by
            #6

            Take as a advice. your line of thinking is among the lines of: "oh, they started a war and destroyed themselves, we will teach them a lesson by starting another war!" makes sense to you?

            I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

            A 1 Reply Last reply
            0
            • A Andrei Straut

              While debugging some problems in an automated console application I ran into this:

              try {
              //some code
              } catch(Exception e) {}

              I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

              class TheClass {

              /\*Overriden the GetType class method so that it returns a different class name than it should,
              it no longer returns the name of the class it's in\*/
              private string GetType() {
                  return "ISyncService";
              }
              
              private int methodThatThrewError() {
                  //some code
                      
                  try {
                      //some other code
                  } catch(Exception e) {
                      /\*We log exceptions by class name, method where it occurred 
                      and exception message, plus optionally stack trace\*/
                      Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
              
                      /\*Also make sure we're always successful\*/
                      return successCode;
                  }
                      
                  return successCode;
              }
              

              }

              Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

              Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

              D Offline
              D Offline
              dandy72
              wrote on last edited by
              #7

              If your coworker never bothers to log exceptions, why would he start looking at the log file now that you're sending inaccurate data to it?

              A 1 Reply Last reply
              0
              • S Sentenryu

                Take as a advice. your line of thinking is among the lines of: "oh, they started a war and destroyed themselves, we will teach them a lesson by starting another war!" makes sense to you?

                I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)

                A Offline
                A Offline
                Andrei Straut
                wrote on last edited by
                #8

                Sentenryu wrote:

                "oh, they started a war and destroyed themselves, we will teach them a lesson by starting another war!" makes sense to you?

                TBH, actually it does, but I may just have a sick mind :omg: . As I said to Patrice, I repeatedly asked for errors to be logged properly, with no result, so this one was somewhat of a last resort, and half-jokingly made. I'm the one working on the code 80% of the time and writing 80% of it, and I don't want to have to track errors that are hidden. I may just be a code Nazi, but I've had to work on legacy projects that had no documentation/code formatting/error handling at all, and it's not pleasant. I try my best to write readable and understandable code, for me as well for those that will come later (as is exactly the case, tomorrow is my last day at the job), and I only ask the same for my colleagues. I can understand when it's not possible for various reasons, but when it does become a habit I take it seriously. There is also the argument that I could take it to management, but I didn't want to do that, as I've known this chap for quite a while (went to college together, and then we've become work mates too for the last couple of years) and he's quite a nice guy. My gesture was not made with bad or harmful intentions, but more like a tongue-in-cheek of what can happen when you don't properly trace your stuff.

                Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                D 1 Reply Last reply
                0
                • D dandy72

                  If your coworker never bothers to log exceptions, why would he start looking at the log file now that you're sending inaccurate data to it?

                  A Offline
                  A Offline
                  Andrei Straut
                  wrote on last edited by
                  #9

                  He'll have to at some point. Suppliers change their feed formats quite often, and something will break eventually, as was the case with the problem I was tracing (one of them changed the positions of some info fields in the feed - a CSV file without any kind of headers).

                  Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                  D 1 Reply Last reply
                  0
                  • A Andrei Straut

                    Sentenryu wrote:

                    "oh, they started a war and destroyed themselves, we will teach them a lesson by starting another war!" makes sense to you?

                    TBH, actually it does, but I may just have a sick mind :omg: . As I said to Patrice, I repeatedly asked for errors to be logged properly, with no result, so this one was somewhat of a last resort, and half-jokingly made. I'm the one working on the code 80% of the time and writing 80% of it, and I don't want to have to track errors that are hidden. I may just be a code Nazi, but I've had to work on legacy projects that had no documentation/code formatting/error handling at all, and it's not pleasant. I try my best to write readable and understandable code, for me as well for those that will come later (as is exactly the case, tomorrow is my last day at the job), and I only ask the same for my colleagues. I can understand when it's not possible for various reasons, but when it does become a habit I take it seriously. There is also the argument that I could take it to management, but I didn't want to do that, as I've known this chap for quite a while (went to college together, and then we've become work mates too for the last couple of years) and he's quite a nice guy. My gesture was not made with bad or harmful intentions, but more like a tongue-in-cheek of what can happen when you don't properly trace your stuff.

                    Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                    D Offline
                    D Offline
                    DerekT P
                    wrote on last edited by
                    #10

                    I wonder how long it will be before your replacement posts this code in "code horrors"... Seriously, if your intention is to "make a point" then it might have been more appropriate to log it with a type of "HowTheHellWouldIKnow" and a message of "So There IS a point to logging after all" rather than deliberately misleading the next poor guy who has to unravel this. If anything, writing incorrect data to the log is just going to make him even LESS likely to log errors, because the log won't be reliable. I understand your frustration (believe me, I understand!) but I'm not convinced that this was the wisest approach. In the worst case, if there's a serious bug and it takes 5 times as long to debug as it should because of the misleading stuff in the log, your company may lose revenue / customers / credibility and ALL your ex-colleagues may suffer. Suggest you email your pal a note pointing out what you've done... :-)

                    A 1 Reply Last reply
                    0
                    • D DerekT P

                      I wonder how long it will be before your replacement posts this code in "code horrors"... Seriously, if your intention is to "make a point" then it might have been more appropriate to log it with a type of "HowTheHellWouldIKnow" and a message of "So There IS a point to logging after all" rather than deliberately misleading the next poor guy who has to unravel this. If anything, writing incorrect data to the log is just going to make him even LESS likely to log errors, because the log won't be reliable. I understand your frustration (believe me, I understand!) but I'm not convinced that this was the wisest approach. In the worst case, if there's a serious bug and it takes 5 times as long to debug as it should because of the misleading stuff in the log, your company may lose revenue / customers / credibility and ALL your ex-colleagues may suffer. Suggest you email your pal a note pointing out what you've done... :-)

                      A Offline
                      A Offline
                      Andrei Straut
                      wrote on last edited by
                      #11

                      DerekTP123 wrote:

                      Suggest you email your pal a note pointing out what you've done... :)

                      No, I think I'll tell him directly.

                      Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                      1 Reply Last reply
                      0
                      • A Andrei Straut

                        He'll have to at some point. Suppliers change their feed formats quite often, and something will break eventually, as was the case with the problem I was tracing (one of them changed the positions of some info fields in the feed - a CSV file without any kind of headers).

                        Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                        D Offline
                        D Offline
                        dandy72
                        wrote on last edited by
                        #12

                        So you're playing these games with your coworker with live, production software?

                        1 Reply Last reply
                        0
                        • A Andrei Straut

                          While debugging some problems in an automated console application I ran into this:

                          try {
                          //some code
                          } catch(Exception e) {}

                          I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

                          class TheClass {

                          /\*Overriden the GetType class method so that it returns a different class name than it should,
                          it no longer returns the name of the class it's in\*/
                          private string GetType() {
                              return "ISyncService";
                          }
                          
                          private int methodThatThrewError() {
                              //some code
                                  
                              try {
                                  //some other code
                              } catch(Exception e) {
                                  /\*We log exceptions by class name, method where it occurred 
                                  and exception message, plus optionally stack trace\*/
                                  Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
                          
                                  /\*Also make sure we're always successful\*/
                                  return successCode;
                              }
                                  
                              return successCode;
                          }
                          

                          }

                          Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

                          Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #13

                          I'm sorry, but I fail to see the funny side. How is the person who takes over from the pair of you going to think when he finds this code? I expect we'll see it posted here again as an example of a code fail. Yes, the original code was wrong, but you have just made the situation 10 times worse, and potentially stored up a huge problem for your employer in the process. The fact that you did this deliberately is shocking.

                          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                          A 1 Reply Last reply
                          0
                          • P Pete OHanlon

                            I'm sorry, but I fail to see the funny side. How is the person who takes over from the pair of you going to think when he finds this code? I expect we'll see it posted here again as an example of a code fail. Yes, the original code was wrong, but you have just made the situation 10 times worse, and potentially stored up a huge problem for your employer in the process. The fact that you did this deliberately is shocking.

                            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                            A Offline
                            A Offline
                            Andrei Straut
                            wrote on last edited by
                            #14

                            Pete O'Hanlon wrote:

                            How is the person who takes over from the pair of you going to think when he finds this code?

                            He won't. It's fixed and my colleague announced. Actually he did find it somewhat funny.

                            Pete O'Hanlon wrote:

                            Yes, the original code was wrong, but you have just made the situation 10 times worse, and potentially stored up a huge problem for your employer in the process

                            I fail to see how I created a huge problem. I did not change the data or interact with it in any way (except fixing what came wrong), I logged something badly instead of not logging it at all, and whoever used the VS debugger would notice it in a flash.

                            Pete O'Hanlon wrote:

                            The fact that you did this deliberately is shocking.

                            Although I do acknowledge it was uninspired and totally unprofessional (I try to take myself seriously, as well as others, and here I was wrong), shocking no, I don't think so. Again, I was wrong for this, and thanks to the CP community for pointing it out. EDIT: Should I delete the thread, or leave it as is?

                            Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                            P 1 Reply Last reply
                            0
                            • A Andrei Straut

                              Pete O'Hanlon wrote:

                              How is the person who takes over from the pair of you going to think when he finds this code?

                              He won't. It's fixed and my colleague announced. Actually he did find it somewhat funny.

                              Pete O'Hanlon wrote:

                              Yes, the original code was wrong, but you have just made the situation 10 times worse, and potentially stored up a huge problem for your employer in the process

                              I fail to see how I created a huge problem. I did not change the data or interact with it in any way (except fixing what came wrong), I logged something badly instead of not logging it at all, and whoever used the VS debugger would notice it in a flash.

                              Pete O'Hanlon wrote:

                              The fact that you did this deliberately is shocking.

                              Although I do acknowledge it was uninspired and totally unprofessional (I try to take myself seriously, as well as others, and here I was wrong), shocking no, I don't think so. Again, I was wrong for this, and thanks to the CP community for pointing it out. EDIT: Should I delete the thread, or leave it as is?

                              Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #15

                              Leave it. Hopefully others can learn from it. Sometimes a quiet word is the right solution to a problem.

                              *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                              CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                              A 1 Reply Last reply
                              0
                              • P Pete OHanlon

                                Leave it. Hopefully others can learn from it. Sometimes a quiet word is the right solution to a problem.

                                *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                                A Offline
                                A Offline
                                agolddog
                                wrote on last edited by
                                #16

                                I have to agree with Pete. The feeling I get reading this thread is that your coworker wrote some bad code out of stupidity/stubbornness/inexperience and you countered that with malice. Shocking doesn't begin to describe it to me. If that code got checked into the repository, you're fired. Sorry to be so harsh, but this is a completely inappropriate way to handle the situation. I have to say, I am in total agreement with you on your notion that logging every caught exception is the proper way to go. Even if your code can continue on properly, it's good to log that. To give a trivial example:

                                int num = 0;
                                try {
                                num = Convert.ToInt32(string);
                                } catch (FormatException e)
                                Log.Info("Couldn't convert " + string + " to int, using default");
                                num = ;
                                }

                                Of course, this is trivial, but you get the idea.

                                K 1 Reply Last reply
                                0
                                • P Patrice STOESSEL

                                  Why don't you speak to this colleague ? Until today, to speak is the best way to explain your point, and to be understood. You might even learn something doing so ... To play more stupid than the stupid is a sure way to failure, for both you and him.

                                  gzo

                                  B Offline
                                  B Offline
                                  BrainiacV
                                  wrote on last edited by
                                  #17

                                  I agree with you, but some people are just bricks. I used to work with this programmer whose opinion was that if his program GPF'd it was the user's fault. All I could do was make his life hell by finding out how fast I could crash his program and then give him a step by step set of instructions on how to reproduce it. He eventually quit and I'm sure he's doing the same at a new location.

                                  Psychosis at 10 Film at 11 Those who do not remember the past, are doomed to repeat it. Those who do not remember the past, cannot build upon it.

                                  1 Reply Last reply
                                  0
                                  • A Andrei Straut

                                    While debugging some problems in an automated console application I ran into this:

                                    try {
                                    //some code
                                    } catch(Exception e) {}

                                    I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

                                    class TheClass {

                                    /\*Overriden the GetType class method so that it returns a different class name than it should,
                                    it no longer returns the name of the class it's in\*/
                                    private string GetType() {
                                        return "ISyncService";
                                    }
                                    
                                    private int methodThatThrewError() {
                                        //some code
                                            
                                        try {
                                            //some other code
                                        } catch(Exception e) {
                                            /\*We log exceptions by class name, method where it occurred 
                                            and exception message, plus optionally stack trace\*/
                                            Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
                                    
                                            /\*Also make sure we're always successful\*/
                                            return successCode;
                                        }
                                            
                                        return successCode;
                                    }
                                    

                                    }

                                    Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

                                    Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                                    S Offline
                                    S Offline
                                    SeattleC
                                    wrote on last edited by
                                    #18

                                    1. A programming language that would even let you do this is broken. I feel so unclean just having read this. 2. Type that into the codebase, and it's only a matter of time before you are the victim; either of forgetting to take it out, or having it used against you. 3. Pranks. Oy! I've worked in organizations where pranks got to be the accepted norm. They are sick and unprofessional organizations. Generally what happens is somebody goes too far. Maybe there is an injury, or a customer gets pranked by accident. Then there is a short, grim meeting where your boss or your division manager or somebody from Personnel lays it on the line saying, "Next prank gets you fired." A better approach is to make the dumb behavior (not logging) an issue with your colleague, and if he doesn't make an attempt to improve, with your team or your manager. Because your colleague can certainly make the pranking an issue with your manager. Then he will have the moral high ground and you will lose traction on getting the undesirable behavior fixed. If you act unprofessionally because your teammate did, that fixes nothing.

                                    L 1 Reply Last reply
                                    0
                                    • A Andrei Straut

                                      While debugging some problems in an automated console application I ran into this:

                                      try {
                                      //some code
                                      } catch(Exception e) {}

                                      I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

                                      class TheClass {

                                      /\*Overriden the GetType class method so that it returns a different class name than it should,
                                      it no longer returns the name of the class it's in\*/
                                      private string GetType() {
                                          return "ISyncService";
                                      }
                                      
                                      private int methodThatThrewError() {
                                          //some code
                                              
                                          try {
                                              //some other code
                                          } catch(Exception e) {
                                              /\*We log exceptions by class name, method where it occurred 
                                              and exception message, plus optionally stack trace\*/
                                              Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
                                      
                                              /\*Also make sure we're always successful\*/
                                              return successCode;
                                          }
                                              
                                          return successCode;
                                      }
                                      

                                      }

                                      Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

                                      Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                                      B Offline
                                      B Offline
                                      BobJanova
                                      wrote on last edited by
                                      #19

                                      I'm going to have to join the crowd who say that: yes, this is funny, and devious, but if that made it to the source control for an actual release then you're a bad developer too. Also I'm pretty sure you'll get a compiler warning for hiding inherited method GetType which should be a bit of a giveaway. And honestly if it was only 15 minutes that you wasted tracking it down then it's not worth getting annoyed by.

                                      A 1 Reply Last reply
                                      0
                                      • A Andrei Straut

                                        While debugging some problems in an automated console application I ran into this:

                                        try {
                                        //some code
                                        } catch(Exception e) {}

                                        I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

                                        class TheClass {

                                        /\*Overriden the GetType class method so that it returns a different class name than it should,
                                        it no longer returns the name of the class it's in\*/
                                        private string GetType() {
                                            return "ISyncService";
                                        }
                                        
                                        private int methodThatThrewError() {
                                            //some code
                                                
                                            try {
                                                //some other code
                                            } catch(Exception e) {
                                                /\*We log exceptions by class name, method where it occurred 
                                                and exception message, plus optionally stack trace\*/
                                                Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
                                        
                                                /\*Also make sure we're always successful\*/
                                                return successCode;
                                            }
                                                
                                            return successCode;
                                        }
                                        

                                        }

                                        Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

                                        Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                                        R Offline
                                        R Offline
                                        RafagaX
                                        wrote on last edited by
                                        #20

                                        Although i love to play pranks, i consider that if this have the remote possibility to reach production, then you're fried (and fired) and as a matter of fact, if your buddy doesn't log errors, i think very unlikely that he sees the log.

                                        CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...

                                        A 1 Reply Last reply
                                        0
                                        • A Andrei Straut

                                          While debugging some problems in an automated console application I ran into this:

                                          try {
                                          //some code
                                          } catch(Exception e) {}

                                          I had lost some 15 minutes tracking this problem (product information not updated in the DB and error log came up empty), and you can imagine I got really angry seeing this stuff. I take it seriously to logging errors, even non-fatal ones. While I can sometimes understand catching Exception, why the hell didn't the guy at least log it? And then...I had a flash of inspiration. So I did the most devious thing I could think of at the time. Knowing that the colleague that wrote this code rarely uses the debugger (he usually debugs the code by placing Console.Outs, builds the application and runs it), I changed that class and the try-catch into the following (comments are mine, and not present in the code):

                                          class TheClass {

                                          /\*Overriden the GetType class method so that it returns a different class name than it should,
                                          it no longer returns the name of the class it's in\*/
                                          private string GetType() {
                                              return "ISyncService";
                                          }
                                          
                                          private int methodThatThrewError() {
                                              //some code
                                                  
                                              try {
                                                  //some other code
                                              } catch(Exception e) {
                                                  /\*We log exceptions by class name, method where it occurred 
                                                  and exception message, plus optionally stack trace\*/
                                                  Helper.logException(this.GetType().ToString(), "RunSyncProcedure", "No error message available", "");
                                          
                                                  /\*Also make sure we're always successful\*/
                                                  return successCode;
                                              }
                                                  
                                              return successCode;
                                          }
                                          

                                          }

                                          Basically, when this exception occurs, it will appear that it happened in a whole different class (and an interface for that matter). That should teach them to log stuff properly, or use the debugger. Yes, I'm a devious SOB, but hey, if they don't care, why should I?

                                          Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                                          B Offline
                                          B Offline
                                          Behzad Sedighzadeh
                                          wrote on last edited by
                                          #21

                                          maybe iam missing something, but if you log e.ToString(), then you have both class name and method name plus line of the code the exception happend.In my helper i just log e.ToString.Any reason?

                                          Behzad

                                          A 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