Monday 21, May 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    About Us    |    Contact Us

  Handling exceptions in java

Here is a java program to handle an exception.
Cut & Paste Script
import java.util.Random;

public class MainClass {
  public static void main(String args[]) {
    int a = 0, b = 0, c = 0;
    Random r = new Random();

    for (int i = 0; i < 32000; i++) {
      try {
        b = r.nextInt();
        c = r.nextInt();
        a = 12345 / (b / c);
      } catch (ArithmeticException e) {
        System.out.println("Division by zero.");
        a = 0;
      }
      System.out.println("a: " + a);
    }
  }

}
 
   
     RELATED SCRIPTS
 
Making Beep sound using java
We are making Beep sound using java....more »
Category : Java Programs Hits : 653
   
Reading file using java
Here is an example of reading text files in java....more »
Category : Java Programs Hits : 615
   
Writing file using java
Here is a java code to write file....more »
Category : Java Programs Hits : 597
   
Compare two strings using java
Here is a java program to compare two strings. It will return the position where they start to differ....more »
Category : Java Programs Hits : 446
   
   
SCRIPT CATEGORIES
 
  C Programs
C Programs scripts
  C++ Programs
C++ Programs scripts
  Java Programs
Java Programs scripts
  JavaScript Examples
JavaScript Examples scripts
  PHP Examples
PHP Examples scripts
  VBScript Examples
VBScript Examples scripts
 
 
 
POPULAR E-BOOKS
 
Download Turning One Into A Million Ebook Turning One Into A Million
   
Download Introduction to Interactive Programming In Java  Ebook Introduction to Interactive Programming In Java
   
Download Introduction to Object-Oriented Programming Using C++  Ebook Introduction to Object-Oriented Programming Using C++
   
Download The Affiliate Marketers Master Guide Ebook The Affiliate Marketers Master Guide
   
Download Blueprints for a successful presentation  Ebook Blueprints for a successful presentation
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz