Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Print table code.... shuts down application

 
David Shepherd
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone see a problem with this code. It seems to occasionally cause my program to just quit. I only use it for testing but I can't find anything wrong.

public static void printTableData(Vector v)
{System.out.println(" --- Table Data ----------------------");
try
{ for(int i =0; i<v.size(); i++)>
{int tempLength =((Vector)v.get(i)).size();
Vector innV =(Vector)v.get(i);
for(int x =0; x<tempLength; x++)>
{
System.out.print(" "+innV.elementAt(x));
}
System.out.print("\n");
}
}
catch(Exception e)
{
System.out.println("table problem");
e.printStackTrace();
}
}
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it just quits, then it isn't an exception causing the problem. Try catching Error and printing the trace.
Yeah, I know this isn't normally done because there is normally nothing the program can do to recover from the problem, however just to figure out what is causing the problem might be worthwhile.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or catch Throwable, which includes both Error and Exception. When you say it "just quits", do you get any error message? If not, you may find it useful to add a bunch of print statements which tell you what part of the program is executing, so the printout actual as a log of the program's activities. This often offers invaluable clues.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic