Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Exception

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Exception

    How to create the your own custoimzed Exception class?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,790
    My Mood
    Mellow
    Thanks
    236
    Thanked 717 Times in 703 Posts

    Default Re: Exception

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Here's useful info on creating your own exceptions.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception

    you can create an customized exception by extending the Exception class

    sample code for you:

    public class MyException extends Exception {

    public MyException(String message)
    {
    super(message);
    //System.out.println(message);
    }

    }




    public class ExceptionDemo {

    public void displayNumbers() throws MyException
    {
    for(int i=0;i<10;i++)
    {
    System.out.println("i= "+i);
    if(i==6)
    {
    throw new MyException("My Exception Occurred");
    }
    }
    }


    public static void main(String[] args) throws MyException {

    ExceptionDemo exceptionDemo = new ExceptionDemo();
    exceptionDemo.displayNumbers();



    }

    }

  4. #4
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception

    Java provides a way to define our own exceptions. It is good practice to defined the custom(user-defined) exceptions for every application. This helps in handling exceptions better and pass additional information along with exception. The hierarchy of custom exceptions can help taking appropriate actions at various module levels.
    For more information visit below link.
    http://java.meritcampus.com/t/155/Us...ned-exceptions

Similar Threads

  1. Replies: 4
    Last Post: February 20th, 2013, 09:01 AM
  2. Replies: 1
    Last Post: February 6th, 2013, 10:21 AM
  3. Replies: 2
    Last Post: August 30th, 2012, 09:45 AM
  4. Replies: 5
    Last Post: September 5th, 2011, 10:31 AM
  5. Replies: 6
    Last Post: March 25th, 2011, 03:42 PM