Closed mwalzer closed 4 years ago
This is expected behaviour - we catch the error, log it, then re-throw the error after catching to preserve the stack trace.
There are a million and one ways to handle errors but we decided to let the program fail noisily and drop me out of the executing process than catch errors rather than have to navigate a code path out of the process. Example below:
private static void CheckFileIsReadableOrComplain(string inputFilePath)
{
try
{
Stream stream = new FileStream(inputFilePath, FileMode.Open);
stream.Close();
}
catch (IOException)
{
logger.Error(String.Format("Unable to open the file: {0}.", inputFilePath));
throw;
}
}
Is the core dump a problem we can work around?
I'm with Mathias on this one: the Console application should not dump core. It should do the most verbose logging possible of the exception and exit - essentially with: main() { try { rest of program } catch (Exception ex) { log(ex); return 1; } return 0; }
On a good day, one then puts #if !DEBUG...#endif markers around the tries and catches so that the exceptions still propagate up to the debugger when testing and debugging.
bump on v1.0.0-b
Implemented fix as per Peter's suggestion
You'll quickly spot the 'intentional' error in the exec: it is
-in
instead of-i
so it looks for the file n. Anyway, opening the inexistant file is attempted, not found, unhandled exception, core dump.