Need help putting Exceptions in my program.
Hey, everyone, time to use my reason for joining the forum.
A few weeks ago we got a project to do. My progress has been swift and my program is complete, I just need to put in some Exceptions to help control the problem. Now I'm not gonna post my entire piece of code, that would take too long I'm just gonna give you a taste.
import javax.swing.*;
public class Main//
{
public static void main(String[]args)
{
Add ad = new Add();// Creates an object of the add class to some addition.
try
{
do
{
String Menu = JOptionPane.showInputDialog("Choose a submenu by entering a number");
int menu = Integer.parseInt(Menu);
//A lot of code
}
while(menu != 5)'
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "An Error Occurred");
}
}
}
The code above is not important, it's just to give you a taste of my program.
See, how I made the try and catch? While going through my program and someone inputs a blank Enter or a string when they're supposed to input a number, the program delivers the message, but does not return me to the menu or to the, for instance, addition sum, they were busy with.
Please help, but keep in mind the code above is just a small sample of the real code, to give you an idea of my main class. The try and catch is all that is important.
Loop;)