Results 1 to 3 of 3
  1. #1
    LogicBrix is offline Member
    Join Date
    Oct 2011
    Posts
    16
    Rep Power
    0

    Question try and catch Problem ...

    .. i dont know where i can put the Try and catch ....

    Java Code:
    public void actionPerformed(ActionEvent e){
        	int num = 0;
        	String emp = " ";
        	String Fname = " ";
        	String Lname = " ";
        	String Mname = " ";
        	String Dep   = " ";
        	String Pos   = " ";
        	String em = " ";
        	
        	emp = txt.getText();
        	Fname = txt2.getText();
        	Lname = txt3.getText();
        	Mname = txt4.getText();
       		Dep = txt5.getText();
        	Pos = txt6.getText();
        	
        	
        	num = Integer.parseInt(emp);
        	
        	
        if(e.getSource() == btn){
        	
        	if(num == 0 || Fname.equals("")|| Lname.equals("") || Mname.equals("") || Dep.equals("")|| Pos.equals("") )
        	{
        			JOptionPane.showMessageDialog(null,"Sorry, fill all the blank");
        		
        	}
        	else{
        		JOptionPane.showMessageDialog(null,"Success");
        	}
        
     		 }
        
        		
        
        
        }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: try and catch Problem ...

    try and catch are for use with exceptions. But there's nothing in that code that is likely to throw an exception.

    Perhaps you could say what you are trying to do, rather than how you are trying to do it. Someone might be able to suggest something.

    -----

    It would be a good idea to follow Java coding conventions and begin variables with a lower case letter and using camelCase for their component parts: fName, lName, etc.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: try and catch Problem ...

    Quote Originally Posted by LogicBrix View Post
    .. i dont know where i can put the Try and catch ....
    Neither do we. Recommended reading: How to ask questions the smart way

    Quote Originally Posted by LogicBrix View Post
    Java Code:
        	int num = 0;
        	String emp = " ";
        	String Fname = " ";
        	String Lname = " ";
        	String Mname = " ";
        	String Dep   = " ";
        	String Pos   = " ";
        	String em = " ";
        	
        	emp = txt.getText();
        	Fname = txt2.getText();
        	Lname = txt3.getText();
        	Mname = txt4.getText();
       		Dep = txt5.getText();
        	Pos = txt6.getText();
    Do you get paid per line of code?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. try and catch problem
    By Masamune1059 in forum New To Java
    Replies: 6
    Last Post: 01-08-2012, 04:47 AM
  2. try catch problem
    By g123456 in forum New To Java
    Replies: 8
    Last Post: 05-17-2010, 06:54 PM
  3. Problem JOptionPane try catch
    By jason99 in forum New To Java
    Replies: 1
    Last Post: 07-10-2009, 10:39 PM
  4. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 10:54 AM
  5. when to use try...catch
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-18-2007, 08:52 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
  •