PDA

View Full Version : JAVA: equivalent call to system("Pause")??


jtrechter
05-04-2005, 07:10 AM
Hi,
I have a simple program like:

package pckg;

public class HelloWorldApp
{
public static void main (String args[])
{
System.out.println ("Hello World!");
}
}

And I'm using .NET to compile which is fine. However, the result screen just appears for 0.1 seconds. I've used the system("Pause") when programming in C++.

I tried Thread.Sleep(500) right after "System.out.println("Hello World!") but get this error "Exception 'java.lang.InterruptedException' is not caught and does not appear in throws clause".

What is the equivalent call in java?
Thanks.

shmoove
05-04-2005, 09:16 AM
That's Java's exception handling. If a method is declared to throw an Exception then you must enclose it in a try..catch block and catch the Exception that can be thrown or one of it's superclasses:

try {
Thread.sleep(500);
}
catch (Exception e) {}


shmoove