RSS

program Negative Number Exception

28 Des

file name :  tugas10.java

  • Source Code
    package tugas10;public class Tugas10 {public static void main(String[] args) {

    try {

    int num = -1; //INPUTAN NEGATIVE

    sampleMethod(num);

    }

    catch(Exception e) {

    System.out.println(“Caught in main.”);

    }

    }

    public static void sampleMethod(int n) throws Exception {

    try {

    throw new NegativeNumberException();

    }

    catch(NegativeNumberException e) {

    System.out.println(“Caught in sampleMethod.”);

    }

    finally {

    System.out.println(“In finally block.”);

    }

    System.out.println(“After finally block.”);

    }

    }

    class NegativeNumberException extends Exception {

    public NegativeNumberException() {

    System.out.println(“Negative Number Exception”);

    }

    public NegativeNumberException(String message) {

    System.out.println(message);

    }

    }

running program :

 
Tinggalkan komentar

Ditulis oleh pada 28 Desember 2011 in java programming

 

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: