Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please solve my problem

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question Please solve my problem

    I have some problem in that code...

     import java.io.*;
    class Demo{
            public static void main(String args[]){
                    try{
                            //
                    }catch(ArithmeticException e){
     
                    }
                    //----------------------------
                    try{
                            //
                    }catch(InterruptedException e){  //Line 1
     
                    }               
                    //------------------------------
                    try{
                            //
                    }catch(Exception e){  //Line 2****
     
                    }               
            }
    }

    In that code only Line 1 is compile error.But I think Line 2 also compile error.Because InterruptedException and Exception are the checked Exception in compile time....Please help me to solve that..


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Please solve my problem

    Please copy and paste here the full text of the compiler's error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Please solve my problem

    In that code only Line 1 is compile error.
    The reason why you have a compilation error with that line is because there is no code/statements
    that might be Interrupted by another process or thread.

    Try to create another thread and run it, then join your main thread inside the try before line 1
    that will make no compilation error. Because your main thread will wait
    for the other thread to finish first before running/execute the next statement.
    But for some instance that your main thread will be interrupted by another thread,
    That's the InterruptedException occurs.

    But in your code, it is clear that there will be no InterruptedExceptions since
    you only have comment with that block before line 1

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    11
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Please solve my problem

    I think "Exception"(I mean top in the Throwable class hierachy) checked in compile time.So any thread when we use compiler must give the error in that case.can you explain why it doesn't give error?? I'm new for Thread,so please explain it in a bit simple......

Similar Threads

  1. please solve the problem
    By liz in forum Threads
    Replies: 1
    Last Post: February 6th, 2014, 05:27 AM
  2. Please solve my problem
    By Supun Pramoda in forum What's Wrong With My Code?
    Replies: 14
    Last Post: December 8th, 2013, 12:14 AM
  3. please solve my problem
    By anarica in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 12th, 2013, 07:35 AM
  4. Need help to solve this problem
    By ahanf in forum Object Oriented Programming
    Replies: 1
    Last Post: June 3rd, 2012, 05:00 AM
  5. need help to solve the problem
    By priyadaradi in forum Member Introductions
    Replies: 1
    Last Post: May 24th, 2012, 10:44 AM