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



Home Answers Viewqa Java-Beginners Try and catch in Exception Handling.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Naulej kumar
Try and catch in Exception Handling.
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


How can we use try and catch block in exception handling?


Advertisement
View Answers

June 8, 2012 at 3:27 PM


Here is an example of Exception handling.

Example:

public class TryCatchExample{
      public static void main(String [] args){
          int a= 10;
          int b= 0;
          int x;
          try{
           x=a/b;
          }catch (Exception er){
              System.out.println("Division by zero");
                    System.out.println(er);
          }
          }
     }

Result Display:

Division by zero
Java.lang.ArithmeticException: / by zero

Description:- We have created a class named TryCatchExample. In the main method, we have declared some variables of integer type. Then to perform exception handling, we have used try and catch block where we have divided the integer value by 0 in the try block. This results in an Arithmetic Exception. The catch block will show this exception.



Related Tutorials/Questions & Answers:
Try and catch in Exception Handling.
Try and catch in Exception Handling.  How can we use try and catch.... Then to perform exception handling, we have used try and catch block where we have...; try{ x=a/b; }catch (Exception er
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 method where Exception handling is required  Code:  class
Advertisements
try catch
); } catch(Exception e) { System.out.println(e...try catch  why following code gives compile time error.please reply...=1;i<=3;i++) { System.out.println(i); try
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... with the same try block, you can raise different types of exceptions. When an exception
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
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.... If no exception occurs, the code inside the catch statement will never
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 :  ...Exception handling mechanism In this tutorial you will learn about exception
Multiple try catch
Multiple try catch      ... block then it will be catch by the catch block. We can have more than one try/catch block. The most specific exception which can be thrown is written on the top
Nested try catch
Nested try catch      ... then it will be catch by the catch block. We can have more than one try/catch... specific exception which can be thrown is written on the top in the catch block
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 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>
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
Exception handling in java
Exception handling in java We are going to discus about Exception handling... when during execution in a program .we are generate of exception try() block and catch() block. We are handle of exception checked and unchecked exception
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
will handle the exception.  The syntax of nested try-catch blocks is given... Nested Try-Catch Blocks       In Java we can have nested try and catch blocks. It means
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  What is the difference between Throw and Throws
exception handling
exception handling  What is an exception and what are the advantages of exception handling mechanism.   Java Exception Exception... a separate block of codes. This is done with the help of try-catch blocks. 4
exception handling
exception handling  explain about exception handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  could you please tell me detail the concept of exception handling
exception handling
exception handling   Give the exception hierarchy of Java.   Please visit the following links: http://www.roseindia.net/java/java-exception/exception-java.shtml http://www.roseindia.net/java/exceptions/exception
Handling Multiple Catch Clauses
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
 

 

 

DMCA.com