Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


suresh kumar yadav
try catch
1 Answer(s)      3 years ago
Posted in : Java Beginners


why following code gives compile time error.please reply.

class ThreadDemo1 extends Thread { public void run() { for(int i=1;i<=3;i++) { System.out.println(i); try { Thread.sleep(1000); } catch(InterruptException e) { System.out.println(e); } } } public static void main(String[]arg) { ThreadDemo1 t1=new ThreadDemo1(); t1.start(); } }


Advertisement
View Answers

July 23, 2011 at 10:12 AM


class ThreadDemo1 extends Thread {
    public void run() {
        for(int i=1;i<=3;i++) { 
            System.out.println(i);
            try {
                Thread.sleep(1000);
                }
            catch(Exception e) {
                System.out.println(e); 
                }
            }
    }
    public static void main(String[]arg) {
    ThreadDemo1 t1=new ThreadDemo1();
    t1.start();
    }
}


Related Tutorials/Questions & Answers:
try catch
try catch  why following code gives compile time error.please reply...=1;i<=3;i++) { System.out.println(i); try { Thread.sleep(1000); } catch(InterruptException e
try catch method in java
try catch method in java  try catch method in java - when and how should i use the try and catch method in Java ?   Please visit the following links: http://www.roseindia.net/help/java/t/java-try.shtml http
Advertisements
java try catch
java try catch  try{ return 1; }catch(exception e){ return 2; } finally{ Return 3; } What is the out put if any exception occurred
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch...; try{ x=a/b; }catch (Exception er.... Then to perform exception handling, we have used try and catch block where we have
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  what is the difference between Throw,Throws and Try&Catch
Nested Try-Catch Blocks
Nested Try-Catch Blocks       In Java we can have nested try and catch blocks. It means..., the control  is transferred to  the next try statement?s catch handlers
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  What is the difference between Throw and Throws
Java try, catch, and finally
Java try, catch, and finally         The try, catch, and finally keywords are Java keywords... exceptions in Java is achieved through the use of the try and catch blocks. Catch
Nested try catch
Nested try catch      ... then it will be catch by the catch block. We can have more than one try/catch...; <TITLE>Nesting try/catch Statements in jsp</TITLE> </HEAD>
Multiple try catch
Multiple try catch      ... block then it will be catch by the catch block. We can have more than one try...;Multiple try/catch in Jsp</TITLE> </HEAD> <BODY> <
Try catch in JSP
Try catch in JSP      ... it is caught inside the catch block. The try catch block in jsp just work as try catch...; <HEAD> <TITLE> Use of Try catch in jsp</TITLE>
Exception Handling with and without using try catch block
Description: Without using try catch block. If you do not want to explicitly make try catch block then to you program write throws Exception to your... is by using try catch block shown in following code sample:  class
Exception Handling : Multiple Catch
Exception Handling : Multiple Catch In this tutorial, we will discuss the use of declaring multiple catch  with the try block. Multiple Catch : A try statement can have multiple catch blocks. Through multiple catch
Handling Multiple Catch Clauses
block, now we will see how to use more than one catch blocks in a single try... in a single try block however every catch block can handle only one type... below:- try{ ??? ??? } catch(<
Nested try
static void main(String args[]) { try { nestedTry(args); } catch... versa.pl explain me class Demo { static void nestedTry(String args[]) { try...]); System.out.println(a/b); } catch (ArithmeticException e) { System.out.println
Nested try
[]) { try { nestedTry(args); } catch (ArithmeticException e...(String args[]) { try { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); System.out.println(a/b); } catch (ArithmeticException e
Try it Editor
Try it Editor  Hello sir...actually i want to add an html,css & js editor like in w3 school try it editor 1.5....can you tell me how i can add it..pllz plzzz rppy soon
Use multiple catch statement in single jsp
Use multiple catch statement in single jsp       In java a single try can have multiple catch statements. The code bound by the try block need not always throw a single
Catch an Exception using EL
Catch an Exception using EL     ... to catch an exception by using the EL. We can't prevent errors, but of course... error codes we should try to show some friendly messages.  In this example
Try Ruby
Try Ruby       Try out Ruby code in this site, by typing the ruby code then see the result. Read full Description
Is catch(){} block synchronized?
Is catch(){} block synchronized?  The code in catch(){} block behaves synchronized. In one block, if I do {write to file1; write to file2}, and in another {write to file2; write to file1}, they deadlock. Is this implicit sync
Maximum number of catches for a try block
Maximum number of catches for a try block  How many catch statements are allowed for a try statement?   Hello Friend, You can use any number of catch statement for a try statement. Thanks
try and finally block
try and finally block  hello, If I write System.exit (0); at the end of the try block, will the finally block still execute?   hii, if we use System.exit (0); statement any where in our java program
try Java Keyword
; try{ <block of code that may throw exceptions> } catch (<... try Java Keyword       The try is a keyword defined in the java programming language. Keywords
java: try finally blocks execution
java: try finally blocks execution  java: try finally blocks execution
The try-with-resource Statement
The try-with-resource Statement In this section, you will learn about newly added try-with-resource statement in Java SE 7. The try-with-resource... or work is finished. After the release of Java SE 7, the try-with-resource
How to Disable Catch-all Emails on CPanel
How to Disable Catch-all Emails on CPanel  Hi, How to disable catch all emails setting on CPanel? Thanks
JSTL <c: catch>
. It works like a try/catch block in java.  If we have any doubt... a try and catch. There is no such thing like try tag. This tag can handle both the try and catch situation.  In this example we are going to use the var
Catching and Handling Exceptions
are below. try catch... the exceptions. These are try, catch and finally clause. The mechanism to catch an exception in Java is to use try and catch block. Every catch block can handle only one
can u plz try this program - Java Beginners
can u plz try this program  Write a small record management application for a school. Tasks will be Add Record, Edit Record, Delete Record, List Records. Each Record contains: Name(max 100 char), Age, Notes(No Maximum Limit
Catching Exception usin c: catch
like a try/catch block in java.  If we have any doubt that the particular... and catch. There is no such thing like try tag. This tag can handle both the try...Catching Exception usin c: catch     
Catching Normal Exceptions
to as normal exceptions.  We have already learned that to catch an exception we use try and catch block.  try { myTestException(); } catch(ExceptionType1 e
JavaScript Exception Handling
JavaScript Exception Handling: Try...catch block help to handle the exception handling, try..catch block works together.  You use the catch statement... of the code occurs in the block of code defined by the try statement
Java finally
; In java, there are three clauses named try, catch and finally used as exception handler components. If the section enclosed within the try block generates any... a good practice to use finally clause after the try and catch block to handle
SCJP Module-6 Question-23
;-"; public static void main(String[] args) { try { throw new Exception(); } catch (Exception e) { try { try { throw new Exception(); } catch (Exception ex) { str += "MI "; } throw new Exception(); } catch
Java Error
that describes the serious problems that a reasonable application should not try to catch... of the applications should not try to catch it. You must not declare a method
The finally Keyword
that is always executed in a trycatch−finally statement. In java, there are three clauses named try, catch and finally used as exception handler components... the try and catch block to handle an unexpected exception occurred in the try
Use of <c:catch> tag of Core JSTL tags
;c"%> <html> <head> <title>Example of tag catch of Core...;${pageContext.request.method=='POST'}"> <c:catch var="... file of code and unzip this file, you will get a folder named  'catch
get UnsatisfiedLinkError when I try to use my JDBC driver.
get UnsatisfiedLinkError when I try to use my JDBC driver.  Why do I get UnsatisfiedLinkError when I try to use my JDBC driver
plz try to clear my doubt for shuffling multi-dimensional array
plz try to clear my doubt for shuffling multi-dimensional array  hi, if v r using Arrays.asList() means, it may shuffle the row wise list only... v...??? plz help me... thanks in advance   Hi Friend, Try the following code
plaz help me i try to compile from last 2 day .
plaz help me i try to compile from last 2 day .   org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 34 in the jsp file: /saveUpdate.jsp name cannot be resolved to a variable 31
plaz help me i try to compile from last 2 day .
plaz help me i try to compile from last 2 day .   org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 34 in the jsp file: /saveUpdate.jsp name cannot be resolved to a variable 31
try to execute this code getting class cast exception, please resolve it.
try to execute this code getting class cast exception, please resolve it.  package test; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; public class Over { static int k
Exception handling mechanism
keywords you can handle exception in java they are as follows: try catch... an exception, but try block must followed by catch or finally. Syntax :  ... : catch block is used to handle the exception.and it must be followed try block
Finally in java
that execute after try/catch block. finally will execute whether exception... to return to the caller from inside try/catch block through a return statement... args[]) { try { int a=5/0; } catch
SCJP Module-6 Question-6
block without 'catch'. 2.No errors. Prints :   Inside try...; Finally must be after 'catch'. Answer : (2) Explanation : Can use 'try... main(String[] args) { try { System.out.println("Inside try"
Java error illegal start of type
catch block to handle the error in the try block.../src/ Illegalstartoftype.java:7: 'try' without 'catch' ... occurred in your code when the starting braces of catch block  is not used
SCJP Module-6 Question-7
finally". 4. Compile error 'catch' without 'try' Answer : (4...; catch{   System.out.println("Inside catch");   }  ... the error in the above code ? 1. No errors. Prints :  Inside try   
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)
How to pass and catch HTML parameters to a Java program using REST services?(without using servlet/jsp)  Hello, I am new to these technologies i.e.... and catch HTML parameters to a Java program using REST services?(without using
SCJP Module-6 Question-9
Given below the sample code : public class SuperClass { static String str = ""; public static void main(String[] args) { try { str += "2"; throw new Exception(); } catch (Exception e) { str += "3"
 

 

 

DMCA.com