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