Is this try catch block enough to ensure the process ran successfully?

protected boolean attemptLaunch()
    {
        try
        {
            System.out.println("Attempting to open '" + name + "'.");

            //Try to open the Process
            new ProcessBuilder(path).start();

            return true;
        }
        catch (IOException e)
        {
            System.out.println("Opening failed. Will retry during next Iteration.");
            return false;
        }
    }

Recommended Answers

All 3 Replies

I think that will catch problems where the OS was not able to load and start the process. I think it will not catch any problems that the new process encounters(eg invalid run parameter values) after it starts to execute.
So, you asked two questions:
"Relying on Try-Catch enough to ensure the Process was successfully started?"
Yes
"Is this try catch block enough to ensure the process ran successfully?"
No

I agree with James. It just catches what you set it to catch. Runtime errors should be handled separately..

It ONLY catches IO errors, which probably means it only catches problems opening the file that starts the process.
It can't possibly catch problems happening at runtime, process crashes, process failing to run because the executable is corrupt, security problems, etc. etc.
For those you'll need to do other things.
Things like monitoring the process's output and error streams of the Process returned by the ProcessBuilder.

There's more information in the javadoc for Process and ProcessBuilder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.