Results 1 to 3 of 3
- 12-08-2009, 03:51 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
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.
So the problem is the exceptions. In the current state, the program gives me: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(); }
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.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)...
Anybody have any idea where I can start looking to understand the problem?
- 12-08-2009, 08:27 PM #2
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
Well I changed the catch slightly and it appears to be working fine now.
Java Code:} catch (Throwable e) { e.printStackTrace(); }
- 12-08-2009, 08:33 PM #3
Senior Member
- Join Date
- Aug 2009
- Location
- Pittsburgh, PA
- Posts
- 282
- Rep Power
- 4
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
-
dealing with (zip) files
By aloula in forum Advanced JavaReplies: 4Last Post: 10-06-2009, 07:32 PM -
Dealing with iReport 3.0.0
By HotEvilGirl in forum New To JavaReplies: 6Last Post: 09-11-2009, 11:32 AM -
Inconsistencies dealing with null
By xcallmejudasx in forum New To JavaReplies: 3Last Post: 05-11-2009, 08:58 PM -
Need help with a simple Java thing involving array of objects
By Jeremy8 in forum New To JavaReplies: 5Last Post: 02-25-2009, 07:14 PM -
Simple program involving military time
By busdude in forum New To JavaReplies: 4Last Post: 10-08-2008, 06:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks