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.









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
Java throw and throws  What is the difference between throw and throws
Advertisements
Java throw ,throws
Java throw ,throws  What is the difference between throw and throws
Java throw and throws Keyword Example
the throw and throws keywords can be used in the Java program. In this 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
throws IOException - Java Beginners
throws IOException  throws IOException means   Hi Friend...://www.roseindia.net/java/exceptions/ http://www.roseindia.net/help/java/i/java-ioexception.shtml http://www.roseindia.net/tutorial/java/scjp/part2/question4.html Thanks
java program example - Java Beginners
java program example  can we create java program without static and main?can u plzz explain with an example
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
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
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. ExampleADS
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 .ADS_TO_REPLACE_1 public class Demo
execution of image example program - Java Beginners
execution of image example program  sir. The example for the demo of image display in java,AwtImage.java,after the execution I can see only the frame used, but not the image to be displayed over it, even after selecting
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
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... the Generics in Java code. ADS_TO_REPLACE_2 Generic List 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
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
throws Exception - RMI
throws Exception  I downloaded your RMI Hello program it works properly. With that same program I replaced for my application. But if run the Server shows the message the Server is connected, but in Client side it throws
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
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  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  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  enter any number and print the number's digits in words. example(enter 123) the output comes(one two three
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 to get current date
Java program to get current date now       In this example program we have to get.../MMM/dd HH:mm:ss format. Here is the full example code
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
Calculator program in Java
Calculator program in Java is used by programmer to add, subtract, multiply or divide two integer numbers that are input by system. In the given example... program in Java package Tutorial; import java.io.*; class calculator
java program for
java program for   java program for printing documents,images and cards
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 example to calculate the execution time
of the program or method by the ending time of the method. In our example java... Java example to calculate the execution time       get execution time This example program
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
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  A Java Program that print the data on the printer but buttons not to be printed
Java Program
Java Program  Problem Statement You are required to play a word-game.... Additionally, each letter in the secret-word is counted only once. For example... and the number of cows and bulls for each word, your program should be able to work out
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
java program
java program  write a program to print 1234 567 89 10
java program
java program  Write a program to demonstrate the concept of various possible exceptions arising in a Java Program and the ways to handle them.  ... in Java
java program
java program  write java program for constructor,overriding,overriding,exception handling
java program
java program  how to write an addition program in java without using arithematic operator
java program
java program  write a java program to display array list and calculate the average of given array
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  java program to implement the reflection of a particular class details like constructor,methods and fields with its modifiers
java program
java program  Write a java program to do matrix addition operation On two given matrices
java program
java program  Write a java program to find the number of Positive numbers in m* n matrix
java program
java program  Write a program to create an applet and display The message "welcome to java

Ads