Results 1 to 2 of 2

Thread: JAVA programming language

  1. #1
    SmithJohnson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    364
    Rep Power
    3

    Default JAVA programming language

    I am learning JAVA programming language. I have little bit knowledge of JAVA.I want to know that why we use an exceptions but I don't know how to throw it. Please give me some proper solution for that. Thanks in advanced.

  2. #2
    Williamsjones is offline Senior Member
    Join Date
    Dec 2009
    Posts
    352
    Rep Power
    3

    Default

    You can use single argument for throw statement, which is a throwable object. Objects are instances of any subclass of the Throwable class. Try to understand following code given below.

    Code:
    class ExceptionDemo extends Exception {
    public ExceptionDemo(String msg){
    super(msg);
    }
    }
    
    public class Test {
    
    static int  divide(int first,int second) throws ExceptionDemo{ 
      if(second==0) 
      throw new ExceptionDemo("can't be divided by zero");
    return first/second;
     }
     public static void main(String[] args) {
      try {
    System.out.println(divide(4,0));
      }
    catch (ExceptionDemo excp) {
    excp.printStackTrace();
      }
      }
    }

Similar Threads

  1. Replies: 0
    Last Post: 08-09-2010, 01:24 PM
  2. web form using asp.net programming language
    By BellWard in forum Programming
    Replies: 3
    Last Post: 07-07-2010, 02:10 PM
  3. learning C programming language
    By HernandezOrtiz in forum Programming
    Replies: 1
    Last Post: 02-19-2010, 01:27 PM
  4. Most Useful Linux Related Programming Language(s)
    By Damario Elonzo in forum Linux/Free BSD
    Replies: 2
    Last Post: 08-18-2009, 07:05 AM
  5. Erlang a programming language
    By ostin55 in forum Programming
    Replies: 0
    Last Post: 07-30-2008, 06:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48