mattbriançon


Cool Debug Trick

March 22nd, 2007 by matt

I just thought of (and used) a cool trick to help debug code.

Say you have a line of code that is throwing an error.
temp += (format.replace("%URL%",ll.getFirst().getURL()).replace("%IMG%",ll.removeFirst().getIMG())+sp);

It doesn’t really matter what this line does. What does matter is that there are clearly several method calls. The problem is you don’t know which part of the line is causing the error.

To fix that you can just split up the line at the commas like so(note: this might not be allowed in all languages – I’m doing this in Java):

temp += (format.replace("%URL%",
ll.getFirst().getURL()).replace("%IMG%",
ll.removeFirst().getIMG()) + sp);

Now when an error is thrown and you go to the line you have a better idea of where to start looking for problems.

No Comments

Leave A Comment