Results 1 to 3 of 3
  1. #1
    fawkes711 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Dealing with exceptions in my simple GUI app involving a process

    Hey there,

    Been using Java for a while now, but haven't learned everything so I started trying out Runtime and Processes and I am stuck in a dilema right now. Also not quite sure if this is the right forum.

    Java Code:
    Runtime rt = Runtime.getRuntime();
            try {
    	Process p = rt.exec("notepad.exe " + file.getPath());
    			
    //	int exitVal = p.waitFor();
    	p.waitFor();
              // System.out.println("ExitValue: " + exitVal);  
    				
                // code for testing in a console
                BufferedReader outStream = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String output = null;
                while ((output = outStream.readLine()) != null){
                	System.out.println(output);}outStream.close();
                	
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    So the problem is the exceptions. In the current state, the program gives me:

    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    Unhandled exception type InterruptedException

    at Convert.actionPerformed(Convert.java:112)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)...
    I know the problem originates from the p.waitFor() line, I'm not even sure if I really need it. Every example code I have read for a simple process/runtime program has similar code, except some of them catch Exceptions in general, and some catch IOExceptions.

    Anybody have any idea where I can start looking to understand the problem?

  2. #2
    fawkes711 is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    Well I changed the catch slightly and it appears to be working fine now.

    Java Code:
    } catch (Throwable e) {
    			e.printStackTrace();
    		}

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    Yeah, this query would probably get more answers in our sister forum on Threads and Synchronization.

    Its documentation shows that waitFor() can throw InterruptedException.
    It was probably not found until runtime because the compiler
    cannot reliably determine whether it has been caught.

    Googling "interruptedexception" did bring up potentially useful notes like Dealing with InterruptedExceptionl

Similar Threads

  1. dealing with (zip) files
    By aloula in forum Advanced Java
    Replies: 4
    Last Post: 10-06-2009, 07:32 PM
  2. Dealing with iReport 3.0.0
    By HotEvilGirl in forum New To Java
    Replies: 6
    Last Post: 09-11-2009, 11:32 AM
  3. Inconsistencies dealing with null
    By xcallmejudasx in forum New To Java
    Replies: 3
    Last Post: 05-11-2009, 08:58 PM
  4. Replies: 5
    Last Post: 02-25-2009, 07:14 PM
  5. Simple program involving military time
    By busdude in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 06:03 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
  •