KevinUp

real world programming

debugging code

Posted by kevinup on February 23, 2009

I was helping another developer debug some code the other day. We had an if statement, that when it was true, it should throw an exception. The problem was the exception was being throw every time even when we knew the expression should have been evaluated to false. I had to laugh when I saw the code and realized what was going on.

bool some_expression_that_evaluates_false = false;
if (some_expression_that_evaluates_false);<-------------
{
    Console.WriteLine("Why is this code executing?");
    throw new Exception();
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>