throws example program java

throws example program java

how to use throws exception in java?

View Answers

July 4, 2012 at 7:25 PM

The throws keyword is used to indicate that the method raises particular type of exception while being processed.

public class StringTest {

  public static void divide() throws ArithmeticException {

        int x = 10, y = 0;
            int z = x / y;
    } 
    public static void main(String[] args) {
        divide();
    }
}

Output:-

Exception in thread "main" java.lang.ArithmeticException: / by zero

Description:- Here is an example of throws clause. We have created a class named ThrowsExample. In the main method, we have declared two variables of integer type and divide the first value by another which is 0. The throws keyword performs exception handling and display the exception.

Ads









Related Tutorials/Questions & Answers:
throws example program java
throws example program java  how to use throws exception in java?   The throws keyword is used to indicate that the method raises..." java.lang.ArithmeticException: / by zero Description:- Here is an example of throws clause. We
Java throw and throws Keyword Example
Java throw and throws Keyword Example In this section we will read about how to throw the caught exception using throw and throws keywords in Java. throws... can be used in the Java program. In this example we will create a simple Java
Advertisements
throws Java Keyword
throws Java Keyword       throws " is a keyword defined in the java programming language. Keywords... : -- The throws keyword in java programming language is applicable to a method
THROWS
THROWS   how can we throw unkown exception using throws clause...?   To throw an exception using throws clause, we have defined a file... { public static void main(String[] args) throws Exception
First Java Program Example
First Java Program Example In this section we will discuss about the first java program example. To create a Java program we would be required to create...;. To demonstrate about a Java program I am giving a simple example. Example Here
Difference between throw and throws in java.
Difference between throw and throws in java. Throws and throw both... will terminate. Throw statement can terminate the program. Using Throws statement... program using throw and throws . public class Demo { public void
malloc in c example program
malloc in c example program  What is malloc in c? Please explain the term using an example in C program. Thanks
Simple JSP program example
Simple JSP program example  Hi, How to make simple jsp program example? I am beginner in JSP and looking for example for getting started with the simple JSP example program. Give me simple jsp program example. Thanks  
Hibernate delete example program
Hibernate delete example program  How to delete an object in Hibernate? In my program I have to write program to delete the data using Hibernate... session.delete(emp); Check the tutorial Hibernate Session.delete() Example
Java Example program to get the current working directory
Java Example program to get the current working directory       This example java program illustrates to get the current working directory (CWD). With the File class
Generics Example Program in Java
Generics Example Program in Java explaining how you use it effectively... the Java Program? The introduction to the Generics is the major step in the Java... in Java code. Generic List Example In this example I will show you how you can
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n; int i; rose(int n,int i) { n=173; i=371; } void out { System.out.println
Hibernate Criteria Query Example Program
Example program? Explain me he Criteria Query API. Thanks   In the Hibernate Criteria Query Example You will find the source code of using Criteria...Hibernate Criteria Query Example Program  Hi, I am new in Hibernate
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
Example to compile a java file with the help of the program
Example to compile a java file with the help of the program... are describing you the way to compile the java file with the help of the java program. The steps involved for compiling the java file from the program are described
java program
java program  write a program showing two threads working simultaneously upon two objects(in theater one object "cut the ticket" and second object... void main(String args[ ]) throws IOException{ MyClass obj1=new MyClass
Java program
Java program  I'm having troubles writing a program that upon entering your height in inches it changes your height to feet and inches, and then also...)throws Exception{ BufferedReader bf = new BufferedReader(new InputStreamReader
java program
java program  write a java program to read a file content into a string object using available and read methods of java bufferedinputstream.   Please visit the following link: http://www.roseindia.net/java/example/java
java program
java program  enter any number and print the number's digits in words. example(enter 123) the output comes(one two three
Java Program
Java Program  I want the answer for this question. Question: Write a program to calculate and print the sum of odd numbers and the sum of even... void main(String[]args)throws Exception{ BufferedReader br=new
java program
java program  A user will input a sequence of positive integers... integers and prints the cumulative total. for example, if the input is 1 7 2 9, the program should print out 1 8 10 10 EVEN:1 ODD:3
Java Program
Java Program  Helle can anyone provide me one example for these question? 1 . Write a method that involves the use of command line parameters and class instantiation. Write a method that processes a file based on given
java program for
java program for   java program for printing documents,images and cards
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime... or not. Example : Here is the code for generating prime number and to check the prime number
Java Program
Java Program for accepting numbers from 1 - 999 and printing them in form of words  Program for accepting numbers from 1 - 999 and printing them in form of words   Java Convert Number to Words The given code accept
Java Program
Java Program  How to Write a Java program which read in a number... out in the standard output. The program should be started like this: java... to be read. In this example, the program should create three threads for reading
Java Program
Java Program  Hi, please share the code to check, if two strings are permutations of each other in java.   Here is an example that prompts the user to enter two strings in order to check whether they are permutation
a Java program
a Java program    Write a Java program to print even numbers from 2 to 1024? Write a Java program to print ? My Name is Mirza? 100 times? Write a Java program to print Fibonacci Series? Write a Java program to reverse a number
java program
java program  write a java program to display array list and calculate the average of given array
Java Program
Java Program  java program to insert row in excel sheet after identifying an object
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix

Ads