0

I'm having trouble getting my InputMismatch working on my program. Do I need some kind of throw for this exception? The program compiles fine, but it dosen't pick up the exception. Can someone please help.

public class EndingListener implements ActionListener
{
	public void actionPerformed(ActionEvent e)
	{
		 if (e.getActionCommand().equals("Convert")){

        		try{
			     int base10;
			     String message, base2; 
					   
			     message = userField1.getText();
					   	
			     BaseConversion test = new BaseConversion();			
                       
                            base10 = Integer.parseInt( message );

                            base2 = test.stackreturn(base10);
                            userField2.setText(base2.toString());
                            } 
                    
        		catch ( InputMismatchException inputMismatchException ){         
       			                                                              
           				userField2.setText("Please Enter a Number");   
        				} 
            } 
                 
		 if (e.getActionCommand().equals("Clear"))
			{
                       userField1.setText("");
                       userField2.setText("");
                 }                  
                 
    }
}
3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by darklich13
0

Thanks for the help I was able to get this to work. Is there a list on the Sun site that shows all the different types of exceptions?

0

Thanks for the help I was able to get this to work. Is there a list on the Sun site that shows all the different types of exceptions?

I would look up (in google) either--

java class Exception 6.0

or

java throwable 6.0

--and I say 6.0 because I assume you want some of the latest information.

From there you can study all of the possible Exceptions. To my knowledge, there should be over 30 of them.

0

Thanks for the help I was able to get this to work. Is there a list on the Sun site that shows all the different types of exceptions?

Any method that you call on the JDK API will document the exceptions that it can throw and the conditions under which they will be thrown. Those that extend Exception are "checked exceptions" and the compiler will make sure that you have try-catch blocks around those or that your method declares that it throws that exception. Exceptions that extend RuntimeException are considered errors. They are "unchecked exceptions" and the compiler does not require try-catch or "throws" declarations for those.

0

Got it, I'm starting to understand this a lot better. Thanks again!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.