Is there anything in cygwin bash that is similar to try-catch in C++?
Posted on 2006-03-29
I am running a command-line app that is nothing more than a script-like executible that calls several other stand-alone apps one after another. Each of these apps takes the output of the previous one as input and generates its own output. One of the intermediate apps crashes from time to time. This causes two types of behavior. If a certain file that this app is supposed to create exists (e.g. from a previous run of this app) then then next app in the pipeline proceeds thus generating garbage results that look credible, which is bad. If the file does not exist then the next app freezes, which is equally bad. I need to try to catch the crash and stop the main app before it proceeds to the next step after the crash. Do you know if there are any utilities in bash that could help me with this?
Note that handling the return code of the main app does not help: it's normal in the case the main app generates garbage and I can't get it if the app freezes. And I also don't have access to the return codes of the individual apps because they are called from within the main app. Finally, the main app is a binary exe file as opposed to a human-readable script file, so I have no way of modifying it.
One workaround for the case when the program freezes is to run it with something like 'expect' and kill it after a certain maximum amount of time. This is not very elegant and may not in certain cases, so I am looking for alternatives.