Results 1 to 6 of 6
  1. #1
    javanew is offline Member
    Join Date
    Mar 2010
    Posts
    49
    Rep Power
    0

    Default please check me this excption

    //after i catch the exception it doesnt print on the console ???why ??

    Java Code:
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    public class FileReader extends JFrame{
    	
    	String s1;
    	String s2;
    	double x1;
    	double x2;
    	double result;
    	String resultStr;
    	JTextField field1; 
    	 JTextField field2 ;
    	 JTextField resultField;
    	public FileReader(){
    		
    		Container c = getContentPane();
    		JPanel p1 = new JPanel();
    		JPanel p2 = new JPanel();
    		
    		c.setLayout(new GridLayout(2,1,5,5));
    		p1.setLayout(new FlowLayout());
    		JLabel l1 = new JLabel("number 1");
    		 field1 = new JTextField(8);
    		 field2 = new JTextField(8);
    		
    	
    		 
    	
    		
    		
    		JLabel l2 = new JLabel("number 2");
    		JLabel l3 = new JLabel ("Result");
    		resultField = new JTextField(8);
    		
    		
    		p1.add(l1);
    		p1.add(field1);
    		p1.add(l2);
    		p1.add(field2);
    		p1.add(l3);
    		p1.add(resultField);
    		
    		JButton divide = new JButton("         Divide           ");
    		divide.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				
    				try{
    				s1 = field1.getText();
    				x1 = Double.parseDouble(s1);
    				
    				s2 = field2.getText();
    				x2 = Double.parseDouble(s2);
    				
    				result = x1 / x2;
    				
    				resultStr = Double.toString(result);
    				resultField.setText(resultStr);}
    				 catch (Exception ex) {
    				      	System.out.println(""); //why it does not print on the console ??? ??????
    				      }
    				
    			}
    		});
    		p2.add(divide);
    		
    		c.add(p1);
    		c.add(p2);
    		
    		
    		
    		
    		setSize(400,400);
    		setVisible(true);
    	}
    	
    	
    }

  2. #2
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    10

    Default

    You're trying to print an empty String. Surprise surprise, nothing shows up.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  3. #3
    javanew is offline Member
    Join Date
    Mar 2010
    Posts
    49
    Rep Power
    0

    Default

    lol i am sorry i forgot to edit it,,
    even if it wasnt an empty string it will pirnt nothing

  4. #4
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    10

    Default

    If a System.out.println() inside a catch block doesn't print, then no exception was caught.
    Ever seen a dog chase its tail? Now that's an infinite loop.

  5. #5
    javanew is offline Member
    Join Date
    Mar 2010
    Posts
    49
    Rep Power
    0

    Default

    why no exception was caught ?? i inserted zero, and there must be an exception

  6. #6
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    312
    Rep Power
    11

    Default

    Dividing by zero with floats and doubles are handled differently then if you do the same with ints.

    double and floats support dividing by 0 by returning infinity. You can get an error if you enter text in there.

Similar Threads

  1. how to check authorisation
    By somesh A in forum Networking
    Replies: 2
    Last Post: 05-07-2010, 05:44 AM
  2. Don't know what to check for
    By Chasingxsuns in forum New To Java
    Replies: 8
    Last Post: 08-26-2009, 06:59 AM
  3. pls check it
    By aRTx in forum New To Java
    Replies: 0
    Last Post: 03-24-2009, 03:35 PM
  4. how to check java
    By funkygarzon in forum New To Java
    Replies: 10
    Last Post: 03-08-2009, 09:39 AM
  5. Check box tag
    By elizaabru in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-26-2008, 03:37 PM

Posting Permissions

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