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.

    A Offline
    A Offline
    Amit Developer
    wrote on last edited by
    #31

    If this is to teach him lesson then I agree with you, considering the fun. :-D But for deployment, it may cause serious problem.

    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.

      L Offline
      L Offline
      Le centriste
      wrote on last edited by
      #32

      Once, as a prank, a guy put an ASP.NET error message as data in the database (with the HTML formatting). Then he told another developer to look into a problem where in a HTML table on of the cells would display the ASP error message. :-\

      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.

        G Offline
        G Offline
        greldak
        wrote on last edited by
        #33

        I could see him getting spoken to to correct his coding and you looking to explain to a new employer why you got sacked for sabataging the codebase.

        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
          dojohansen
          wrote on last edited by
          #34

          FAIL. Sorry to be a party pooper, but your evil intentions would not be fulfilled by that. You haven't overridden the GetType method. You've hidden it. And that means the compiler will only bind to the implementation if invoked on a reference of type TheClass. And it's unlikely anyone would call GetType on the thing if it's already declared to be TheClass (although the run-time type of course could be a descendant). So, since GetType isn't virtual it'd still return "TheClass" and your colleague would go to the code and see that you've attempted to fool him. (If you guys have decent source control anyway.) I do sympathize with your sentiments though. But frankly it is often the project managers who are at fault, because rather than foster a culture where mistakes are openly discussed, not for the purpose of punishment but for education, they tend to reward people who "are positive". In my experience that's often people who aren't competent enough to see the myriad things that are usually F-ed up in... well, any codebase I've come across.

          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.

            Z Offline
            Z Offline
            zenwalker1985
            wrote on last edited by
            #35

            Andrei Straut wrote:

            Yes, I'm a devious SOB, but hey, if they don't care, why should I?

            If you didnt, then you and that person do not have/make/create any difference. Its just like watching a crime happening and ignoring it than atleast reporting.

            My cUr10U5 w0rlD

            1 Reply Last reply
            0
            • S SeattleC

              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 Offline
              L Offline
              Lost User
              wrote on last edited by
              #36

              Quote:

              "A programming language that would even let you do this is broken." -SeattleC++

              . Have you ever actually used C++, at all? I'm guessing no, otherwise you'd realize that it's quite capable of doing truly horrible things...

              S 1 Reply Last reply
              0
              • L Lost User

                Quote:

                "A programming language that would even let you do this is broken." -SeattleC++

                . Have you ever actually used C++, at all? I'm guessing no, otherwise you'd realize that it's quite capable of doing truly horrible things...

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

                Joe_Dert wrote:

                Have you ever actually used C++, at all? I'm guessing no, otherwise you'd realize that it's quite capable of doing truly horrible things...

                This is hardly to the point. And yeah, I've used C++. Since you were in middle school, I'm guessing. It may well be true that it's a poor workman who blames his tools. But it's also true that it's a deranged colleague who thinks up ways to deliberately damage shared tools and then checks their perverse thoughts in. And then brags about it.

                L 1 Reply Last reply
                0
                • S SeattleC

                  Joe_Dert wrote:

                  Have you ever actually used C++, at all? I'm guessing no, otherwise you'd realize that it's quite capable of doing truly horrible things...

                  This is hardly to the point. And yeah, I've used C++. Since you were in middle school, I'm guessing. It may well be true that it's a poor workman who blames his tools. But it's also true that it's a deranged colleague who thinks up ways to deliberately damage shared tools and then checks their perverse thoughts in. And then brags about it.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #38

                  You're dodging the issue, he did something devious, yes, but, that wasn't my point. Pay attention, you said that any language that allowed him to do what he did was broken, to which I responded(more or less), that C++ is far worse in that regard. (ie: By your reasoning, C++ is broken, because it has many mechanisms which can be abused to do devious things.) Furthermore, I'd suggest that you take some of your "assumed" wisdom of years, and at least try act the part of the wise older man if you want to play the: "I've been coding since you were in diapers" card. Let's be frank, I had quoted you, so, assuming you speak English, you know what I meant, so, either you're a troll, illiterate, or perhaps just senile? Best case scenario, I'm willing to conclude there was some sort of misunderstanding.

                  1 Reply Last reply
                  0
                  • P Pete OHanlon

                    Time to point out that this is C# code.

                    *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

                    S Offline
                    S Offline
                    shiprat
                    wrote on last edited by
                    #39

                    ...you mean to tell me that C# won't run on my doorbell?

                    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.

                      N Offline
                      N Offline
                      Nitin S
                      wrote on last edited by
                      #40

                      hahaha lol... clever idea :D

                      ============================================ The grass is always greener on the other side of the fence

                      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