Wrap main in try catch
This commit is contained in:
@@ -12,29 +12,52 @@ namespace EtchBendLines
|
||||
static Etcher etcher = new Etcher();
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
||||
var files = Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories);
|
||||
|
||||
etcher.EtchLength = double.Parse(ConfigurationManager.AppSettings["EtchLength"]);
|
||||
etcher.MaxBendRadius = double.Parse(ConfigurationManager.AppSettings["MaxBendRadius"]);
|
||||
etcher.EtchLength = GetAppSettingAsDouble("EtchLength");
|
||||
etcher.MaxBendRadius = GetAppSettingAsDouble("MaxBendRadius");
|
||||
|
||||
if (files == null || files.Length == 0)
|
||||
{
|
||||
Console.WriteLine($"No DXF files founds. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
|
||||
PressAnyKeyToExit();
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
foreach (var file in files)
|
||||
{
|
||||
etcher.AddEtchLines(file);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"An error occured: {ex.Message}");
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
PressAnyKeyToExit();
|
||||
}
|
||||
|
||||
static double GetAppSettingAsDouble(string name)
|
||||
{
|
||||
double v;
|
||||
|
||||
try
|
||||
{
|
||||
return double.Parse(ConfigurationManager.AppSettings[name]);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new Exception($"Failed to convert the value of AppSetting[\"{name}\"] to double");
|
||||
}
|
||||
}
|
||||
|
||||
static void PressAnyKeyToExit()
|
||||
{
|
||||
Console.WriteLine("Press any key to exit.");
|
||||
|
||||
Reference in New Issue
Block a user