capturing ctrl-C exception

Hello -

I'm new to Java so maybe this is a basic question: how can I capture ctrl-C in my program?

I used the following code in main() but it doesn't seem to work:

try{

parseCmdline(args);

validateCmdline();

do{

line=getStatsLine(counter);

outputLine(line, counter);

sleepThd.sleep(interval * 1000);

...

}while (alive);

if (summarySet) outputSummary(titlesStr, counter);

}catch (Exception ex){

if (exinstanceof InterruptedException){

if (summarySet) outputSummary(titlesStr, counter);

System.exit(0);

}elseif (exinstanceof RuntimeException){

throw (RuntimeException) ex;

}

}

I need to be able to detect a ctrl-C to print out some information before exiting. Any help is appreciated.

Thanks.

[1505 byte] By [wsayyeda] at [2007-10-2 2:47:36]
# 1
It'd be much better to register a shutdown hook.See http://java.sun.com/developer/TechTips/2000/tt0711.htmlAnd http://www.mcqueeney.com/roller/comments/tom/Weblog/using_java_shutdown_hook_toHope this helps.
JimDinosaura at 2007-7-15 20:41:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2
You can also write a signal handler. This only works on Sun's JVM.
Peter-Lawreya at 2007-7-15 20:41:20 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...