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 8 of 8

Thread: Article: Create your own Exceptions!

  1. #1
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Article: Create your own Exceptions!

    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code


  2. #2
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi!
    Kindly help me to add exception handling in my program. Suppose someone entered text instead of integer. I have just begin learning and need your help.
    import java.util.Scanner;
     
    public class Calci
    { 
     
     public static void main(String args[])
     {
      for(;;)
      {
       int choice;
       Scanner in = new Scanner(System.in);
       System.out.println("*****************MENU***********************");
       System.out.println("1.Add Numbers " + "      2.Substract Numbers");
       System.out.println("3.Multiply numbers " + " 4.Divide Numbers");
       System.out.println("*************Press '5' to Exit**************");
       System.out.println(" Enter your menu Choice");
       choice=in.nextInt();
     
     
       switch(choice)
       {
        case 1:
        int addr,addl,sum=0;
        System.out.println("How many nos you want to add");
        addr=in.nextInt();
        int a[]=new int[addr];
        System.out.println("Enter " + addr + " numbers");
        for(addl=0;addl<addr;addl++)
        {
         a[addl]=in.nextInt();
         sum = sum + a[addl];
         System.out.println("The sum of Numbers is: " + sum);
        }
        break;
     
        case 2:
        int sub2,sub1,subl;
        System.out.println("Enter the 1st number");
        sub1=in.nextInt();
        System.out.println("How many numbers you want to substract from 1st number");
        sub2=in.nextInt();
        int s[]=new int[sub2];
        System.out.println("Enter " + sub2 + " numbers");
        for(subl=0;subl<sub2;subl++)
        {
         s[subl]=in.nextInt();
         sub1 = sub1 - s[subl];
         System.out.println("The result of subtraction is: " + sub1);
        }
        break; 
     
        case 3:
        int mloop, mul,mresult=1;
        System.out.println("How many nos you want to multiply");
        mul=in.nextInt();
        int m[]=new int[mul];
        System.out.println("Enter " + mul + " numbers");
        for(mloop=0;mloop<mul;mloop++)
        {
         m[mloop]=in.nextInt();
         mresult=mresult*m[mloop];
         System.out.println("The result of multiplication is: " + mresult);
        }
        break;
     
        case 4:
        int div1,div2,divloop;
        System.out.println("Enter the dividend");
        div1=in.nextInt();
        System.out.println("How many times you want to divide the divisor");
        div2=in.nextInt();
        int d[]=new int[div2];
        System.out.println("Enter " + div2 + " divisors");
        for(divloop=0;divloop<div2;divloop++)
        {
         d[divloop]=in.nextInt();
         div1=div1/d[divloop];
         System.out.println("The result of division is: " + div1);
        }
        break;
     
        default:
        System.out.println("Wrong Choice");
        System.exit(0);
        }
       }
      }
    }

  3. #3
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Article: Create your own Exceptions!

    Please don't hijack old threads Brajraj, always create your own thread if you have a problem.
    In the meantime, the exception you're looking to handle is InputMismatchException.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Location
    Philippines
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This was helpful..

  5. #5

    Default Re: Article: Create your own Exceptions!

    You have given <a href=”https://www.thursdayboots.store”>Great information</a> <a href=”https://www.thursdayboots.store/2020/11/Mens-Chelsea-thursday-capital-Boots-.html”>v</a><a href=”https://www.thursdayboots.store/2020/11/Womens-Ankle-Thursday%20-Boots.html”>e</a><a href=”https://www.thursdayboots.store/2020/11/Pairs-Dress-Shoe-Laces.html”>r</a><a href=”https://www.thursdayboots.store/2020/11/Pairs-Dress-Shoe-Laces.html”>y</a><a href=”https://www.thursdayboots.store/2020/11/Scott-Chukka-thursday-Boot.html”>g</a><a href=”https://www.thursdayboots.store/2020/11/thursday-boots.html”>o</a><a href=”https://www.thursdayboots.store/2020/11/women-Winter-Boots-USA.html”>o</a><a href=”https://www.thursdayboots.store/2020/12/top-five-thursday-boots-captain.html”>d</a><a href=”https://www.thursdayboots.store/2020/12/Thursday-Boots-Review-Story.html”>i</a><a href=”https://www.thursdayboots.store/2020/12/shine-and-clean-leather-boots.html”>n</a><a href=”https://www.thursdayboots.store/2021/01/Thursday-Boots-Captain-Review.html”>f</a><a href=”https://www.thursdayboots.store/2021/02/Ugg-Boots-For-Men.html”>o</a><a href=”https://www.thursdayboots.store/2021/02/Printed-Shoes-india.html”>r</a><a href=”https://www.thursdayboots.store/2021/02/Advantages-of-using-trekking-shoes.html”>ti</a><a href=”https://www.thursdayboots.store/2021/02/Chelsea-boots.html”>on</a>, I was searching for such information for a long time. Today the search is over, thank you very much

  6. #6
    Junior Member
    Join Date
    Aug 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Article: Create your own Exceptions!

    ...

  7. #7
    Junior Member
    Join Date
    Nov 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Article: Create your own Exceptions!

    It was Great Reading this article. also visit:
    <a href="https://www.fita.in/java-and-j2ee-training-in-chennai/">Java Training in Chennai</a>

  8. #8
    Junior Member
    Join Date
    Sep 2023
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Article: Create your own Exceptions!

    In the realm of education, the journey to success is a thrilling adventure filled with boundless opportunities for personal growth and achievement. The concept of seeking assistance by contemplating <a href="https://allassignmentexperts.com/online-exam-helper">"Pay Someone To Take My Exam"</a> can be reimagined in a positive light, emphasizing the potential within each student to conquer academic challenges and thrive through their own dedication and effort.

    The academic landscape often presents students with rigorous assessments, and the desire to excel naturally arises. However, it's essential to recognize that these challenges are not insurmountable obstacles but stepping stones toward realizing one's true potential. Rather than seeking shortcuts, students are encouraged to embrace the incredible rewards that come with genuine effort.

    One of the most inspiring aspects of education is the transformative journey it offers. Education transcends the mere acquisition of knowledge; it's a pathway to self-discovery and personal growth. By engaging wholeheartedly with the learning process, students unlock their inherent abilities, refine their critical thinking skills, and evolve as individuals, empowered to tackle life's challenges.

    The pressures associated with academic performance can indeed be daunting, but they need not be viewed as burdens. These pressures serve as catalysts for personal development, fostering resilience, determination, and the ability to surmount adversity. When approached with a positive mindset, challenges become opportunities to thrive and shine.

    Furthermore, the pursuit of knowledge itself is a source of joy and fulfillment. Each subject offers a unique adventure, an opportunity to explore, question, and deepen one's understanding of the world. The intrinsic motivation that stems from curiosity and a love for learning is a driving force that leads to authentic academic success.

    Achieving excellence in academia goes beyond grades; it signifies the attainment of knowledge, skills, and a sense of accomplishment. The journey instills confidence, paving the way for scholarships, internships, and a bright future filled with prospects. It is a testament to one's unwavering dedication and an affirmation of their ability to rise to the occasion.

    Moreover, the path to academic success is not solitary but a collective effort. Collaboration with peers, teachers, and mentors enhances the learning experience. Study groups, seeking clarification on challenging topics, and engaging in meaningful discussions foster camaraderie, creating a vibrant educational community where success is shared and celebrated.

Similar Threads

  1. Create your own Exceptions!
    By newbie in forum Java Programming Tutorials
    Replies: 3
    Last Post: September 6th, 2013, 11:51 AM
  2. problems with exceptions
    By gerry123 in forum Exceptions
    Replies: 6
    Last Post: July 23rd, 2011, 07:00 PM
  3. How To add my own Exceptions
    By Newtojava in forum Object Oriented Programming
    Replies: 1
    Last Post: September 2nd, 2010, 07:43 AM
  4. Java Exceptions
    By Vinceisg0d in forum Java Theory & Questions
    Replies: 2
    Last Post: March 13th, 2010, 12:25 AM