Using a message box to display errors
I have a program that uses Swing componants to make various system calls. I am wanting to display (or trap) any errors that occur while running the command and display the error(s) in a single message box.
Here is a sample of the code for one of my system calls...
privatevoid btn_CreatereplicaActionPerformed(java.awt.event.ActionEvent evt){
// TODO add your handling code here:
String Work = txt_Workdir.getText();
String Export = txt_Exportdir.getText();
String Host = txt_Hostname.getText();
String command = ("cmd /c multitool mkreplica -export -workdir " + Work +" -nc -out " + Export +" hostname:" + Host);
Process p =null;
try{
p = Runtime.getRuntime().exec(command);
}catch (IOException ex){
ex.printStackTrace();
}
}
Curretly if the user does something wrong when running the "command" the program just sits there (unlike a cmd prompt that displays the error). How do I get an error (if any) to pop up in a message box?
Thanks
[1477 byte] By [
yelllow4ua] at [2007-11-27 11:04:51]

I tried something like this but the dialog never pops up...
private void btn_CreatereplicaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Object frame = null;
String result = null;
String Work = txt_Workdir.getText();
String Export = txt_Exportdir.getText();
String Host = txt_Hostname.getText();
String command = ("cmd /c multitool mkreplica -export -workdir " + Work + " -nc -out " + Export + " hostname:" + Host);
Process p = null;
try {
p = Runtime.getRuntime().exec(command);
} catch (IOException ex) {
ex.printStackTrace();
}
}
Scanner s = new Scanner(p.getInputStream());
while(s.hasNextLine()) {
sb.append(s.nextLine()+"\n");
result = sb.toString();
}
JOptionPane.showMessageDialog((Component) frame, result);
OK.....I got some of it working.
private void btn_RenameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String VOBpath = txt_VOBpath.getText();
String CReplica = txt_Currentrepname.getText();
String NReplica = txt_Newrepname.getText();
String command = ("cmd /c multitool rename replica:" + CReplica + " "+ NReplica);
File filepath = new File(VOBpath);
Process p = null;
try {
p = Runtime.getRuntime().exec(command, null, filepath);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null,
"Cannot Rename Replica: " + ex.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
return;
}
}
So far so good. Anyone know how to catch an application exception. For instance if I run this command from the DOS prompt without java and I "accidentally" screw up the command I get and error like:
Here is the command that is run from the DOS prompt...
multitool rename Boeing replica:Boeing2
Here is the error I get...
multitool: Error: Pathname not found: "Boeing"
When I run this from my Java program I am assuming that this would be an application error since its just a system call.
I tried something like....
catch (ApplicationException ex) {
JOptionPane.showMessageDialog(null,
"Cannot Rename Replica: " + ex.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);
}
But when I add this code I don't get the error popping up like I would expect....Any ideas?
Thanks.