Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using the debugger

Reply
Thread Tools

using the debugger

 
 
gerrymcc@indigo.ie
Guest
Posts: n/a
 
      08-28-2003
Hi,
I've got a loop which is going through an array, and I'm getting an
array index out of bounds exception. Usually to find this sort of
error I'd use System.out.println() or look at the code until the penny
drops, but I think it must be quicker to use the debugger. I want to
see the local variables in the loop, so I recompiled the class with
the loop, and the main class. The debugger says to recompile with -g
so I did:
javac -g TheMainClass.java, and javac -g TheLoopClass.java.
Then when I run the program and the debugger stops at the exception,
I type locals and the debugger still says recompile with -g.
Does that mean I need to recompile every class the program is using?
Also, is there any tutorial or instructions for using the debugger?
Documentation for any standard debugger would probably explain some of
the general priciples I need to know.
Thanks for any help,
Gerard

 
Reply With Quote
 
 
 
 
Harald Hein
Guest
Posts: n/a
 
      08-29-2003
"" wrote:

> Usually to find this sort
> of error I'd use System.out.println() or look at the code until
> the penny drops, but I think it must be quicker to use the
> debugger.


Congratulations! A lot of programmers can't even be bothered to touch a
debugger. See the recent discussion about logging vs. debugging where
many pulled a lot of fake arguments why logging is sooooooo great.

Knowing how to efficiently use a debugger is a huge advantage and can
can make you the king of the town.

> I want to see the local variables in the loop, so I
> recompiled the class with the loop, and the main class. The
> debugger says to recompile with -g so I did:
> javac -g TheMainClass.java, and javac -g TheLoopClass.java.
> Then when I run the program and the debugger stops at the
> exception, I type locals and the debugger still says recompile
> with -g. Does that mean I need to recompile every class the
> program is using?


It is difficult to say, because it depends on the inner working of the
debugger. I never studied the java debugger in detail, but you should
at least compile everything which you want to trace, set a breakpoint
on, or just display with -g. And because you dont know in advance what
you want to see (you never know where debugging leads you to), it is
best to compile everything with -g.

If you have the resources (if your program doesn't get to large or to
slow with -g) it is a good habbit to always compile everything with -g
while you develop the program. Add the flag to your ant scripts or
makefiles. Then you don't need any extra steps when you decide it is
time for a debugger. Which is another big advantage over the
System.out.println shotgun approach. If you compile everything with -g
you can start the debugger whenever you want. If you use println you
always have to add more to your code and recompile.

> Also, is there any tutorial or instructions for
> using the debugger?


The only one I am aware of is the one in Sun's SDK dokumentation. It
lists the commands. You maybe want to get a better debugger. All the
free IDEs have better ones than Sun's command line tool. It can't hurt
to know Sun's tool in case of emergency, but for day to day work it is
not the best to use.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help getting a debugger going for IE - any free debugger aflat362 Javascript 7 12-07-2006 10:51 PM
Neither IE-Debugger or Mozilla/Venkman debugger can step through dynamically added code? Robert Oschler Javascript 1 09-05-2005 07:17 AM
ISO: stack trace without using a debugger lvirden@gmail.com C Programming 1 03-02-2005 03:11 PM
Using a debugger on a JSP page Steve Java 1 01-08-2005 03:07 AM
JRun and using a Java Debugger Steve Java 3 11-30-2004 09:15 AM



Advertisments