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

 
 


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

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

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 Pages:
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
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
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
java try catch  try{ return 1; }catch(exception e){ return 2; } finally{ Return 3; } What is the out put if any exception occurred
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
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
[]) throws Exception { int id; int grade; String grades = new String(); try{ id...Exception Handling  Hi, I really appreciate the help I have gotten,I... sick mid way through this course and have found it impossible to catch up
Exception Handling
[]) throws Exception { int id; int grade; String grades = new String(); try...Exception Handling  Hi, I really appreciate the help I have gotten,I... sick mid way through this course and have found it impossible to catch up
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
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
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>
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
Java exception handling
Java exception handling  How does a try statement determine which catch clause should be used to handle an exception
Java exception handling
Java exception handling  How does a try statement determine which catch clause should be used to handle an exception
Java exception handling
Java exception handling  What happens if a try-catch-finally statement does not have a catch clause to handle an exception that is thrown within the body of the try statement
Exception Handling - Java Beginners
method instead of try and catch exception handler. For instance, public static...Exception Handling  hi,can u pls make me understand d clear cut difference between throw n throws keyword... n how can we make our own exception..i
Exception Handling
; while (num != -1) { try { num = input.nextInt(); } catch (Exception e...Exception Handling You all are aware of Exceptions and the methods to handle... Exception Handling. Through the given code, you will come to know the use
Java Exception - Exception Handling in Java
Java Exception - Exception Handling in Java  ... and catch the errors using catch() block. Exception turns the direction of normal... code you will see that how the exception handling can be done in java program
Exception Handling
Exception Handling      ... the part of the program which generate the error in the try{} block and catch the errors using catch() block. Exception turns the direction of normal flow
Exception Handling in Java
which generate the error in the try{} block and catch the errors using catch... occurred in the program. For more details about exception handling click on the following links Exception Handling in Java Example to show exception
Java null pointer exception handling
Java null pointer exception handling   What... pointer exception handling What is Java NullPointerException? In Java... check method arguments for Null values. Try and catch block can also prove
PHP  Exception Handling
. In PHP there are three blocks in Exception Handling : try, catch, and throw. i... try { throw new Exception("Some error message"); } catch(Exception... the try block <br/>"; myNumber(22,2); } //catch the exception inside
Handling exception in jsp - JSP-Servlet
Handling exception in jsp  Hi Here is the sample code of servlet...{ // } catch(Exception e){ } Please send me full code because your posted code... this exception to jsp. (this is ok) Now i need to handle this exception in my jsp
Exception Handling
Exception Handling      ... of the program which generate the error in the try{} block and catch the errors using catch() block. Exception turns the direction of normal flow of the program
Catching and Handling Exceptions
an exception in Java is to use try and catch block. Every catch block can handle only one type of exception however you can use more than one catch clause in a single try... the exception to occur. Then the try block is followed by the catch block
Java : Exception Handling
are using try and catch block to handle exception. We put all the code in try block...Java : Exception Handling In this section we will discuss about  JAVA Exception Handling with simple example. Exception Handling : An exception
java exception handling - Java Beginners
java exception handling  hi while i am compailing the program given...*; class insufbal extends Exception { public insufbal(String str) { super..._bal=0.0; } public void init() { String temp; try { System.out.println
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
java exception handling - Java Interview Questions
java exception handling   hi to all , this afsar i have one doubt.please clarify it. while handling exception write try catch and finally blocks. the scenario is P v S main(---) throws exception { try
Exception handling in Objective-C
on. These are four compiler directives that are used for exception handling- 1. @try: block... Exception handling in Objective-C       Objective-C provide exception handling
try Java Keyword
of  an exception object. -- Every try block in java programming language must be followed by a one catch or finally clause at least. -- In exception handling mechanism, if an exception class is not handled by any catch block
Exception Handling in java
Exception Handling in java  what is advantage to catch smaller exception first and then normal exception. I mean we normally catch SQLException first and then Exception.   Hi, The exceptions should be from
Nested try
static void main(String args[]) { try { nestedTry(args); } catch... different outputs ie my exception gets executed first then finally block and vice versa.pl explain me class Demo { static void nestedTry(String args[]) { try
Nested try
[]) { try { nestedTry(args); } catch (ArithmeticException e... is converted to int and gives 1. java Demo 2 0, it will give exception, the try...(String args[]) { try { int a = Integer.parseInt(args[0]); int b
Java exception handling
Java exception handling  What is the catch or declare rule for method declarations
Java exception handling
Java exception handling  Does the order of placing catch statements matter in the catch block
Catch an Exception using EL
Catch an Exception using EL          In this example we are going to catch... to catch an exception using EL in the page where we are going to catch
Java exception handling
Java exception handling  What classes of exceptions may be caught by a catch clause
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  what is the difference between Throw,Throws and Try&Catch
Using throw keyword in exception handling in Core Java
fileInStrm = null; try { fileInStrm = new FileInputStream(fileName); } catch...); } catch (Exception ex) { System.out.println("in main caught"...Description: Core Java Throw Function is used for throwing the exception
Throw,Throws, n try and Catch
Throw,Throws, n try and Catch  What is the difference between Throw and Throws
Exception handling - JSP-Servlet
Exception handling  I have added DSN 'online_exam' in Administrative... the following exception type Exception report message description The server.... exception org.apache.jasper.JasperException
exception
); } catch(Exception e){ System.out.println(e...exception  example for numberformat exception   Hi Friend, Try the following code: class NumberFormatExceptionEx{ public static void
JDBC4.0-SQL Exception Handling Enhancements
JDBC4.0-SQL Exception Handling Enhancements Exception handling is an important... enhancements in SQLException handling. The following are some of the enhancements made... programmers to write more portable error-handling code. There are two new
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you...(String args[]) { int d, a; try { d = 0; a = 42 / d; System.out.println
Enhanced SQL Exception Handling
: try{ // Some Database Access Code }catch(SQLException exception... as a returned exception. try{ // Some Database Access Code }catch... Enhanced SQL Exception Handling      

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.