Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JAVA: equivalent call to system("Pause")??

    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.

  2. #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    try {
      Thread.sleep(500);
    }
    catch (Exception e) {}
    shmoove


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •