Skip to content

Commit

Permalink
Give better message if key not found. Throw instead of exit
Browse files Browse the repository at this point in the history
Ideally a program should only have one call to exit and all exceptions should be caught and logged.
  • Loading branch information
PeterVermont committed Mar 11, 2019
1 parent 870b9b9 commit e448552
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions DaySim.Framework/Persistence/ImporterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,13 @@ private static void GenerateMethodCode(ILGenerator il, Type type, Dictionary<str

try {
element = index[attribute.ColumnName];
} catch (KeyNotFoundException) {
} catch (KeyNotFoundException keyNotFoundException) {
string message = string.Format("The column '{0}' for object of type {1} was not found in filename: {2}", attribute.ColumnName, type, inputPath);
Console.WriteLine(message);
if (Global.PrintFile != null) {
Global.PrintFile.WriteLine(message);
}
Environment.Exit(0);

return;
throw new KeyNotFoundException(message, keyNotFoundException);
}

if (property.PropertyType == typeof(double)) {
Expand Down

0 comments on commit e448552

Please sign in to comment.