Here's the situation. My program will be able to start with an argument
(a path to a file) and then run a batch of commands in that file. So if
an argument is provided to the main method, the program logic moves to
the classes/methods that execute the batch (instead of s normal, GUI
driven program execution).
Should an error occur somewhere during the batch, I really need to
catch it, so that I can return my main method with an errorlevel. But
at the same time, I would like to rethrow any exception I cannot
handle. So here's the problematic code:
//------------------------------------------------------------
public int Main(string[] args)
{
return RunScript(args[0]);
}
//------------------------------------------------------------
public int RunScript(string filepath)
{
try
{
// Do dangerous stuff.
}
catch (System.Exception exc)
{
if (exc is MyHandledException)
{
// Do intelligent stuff.
}
else
{
return 1;
throw exc;
}
}
}
//------------------------------------------------------------
Is the final part even ok? Do I need the Finally statement for this?
Your thoughts.