fix: safeManager error handeling & Load fix
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -18,10 +19,14 @@ namespace CarManagerV3
|
||||
public static void InitializeImageFolder()
|
||||
{
|
||||
string path = "images";
|
||||
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
// Do not catch here. If we cannot create our images folder, the program wont work.
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,15 +52,18 @@ namespace CarManagerV3
|
||||
FetchImage(car);
|
||||
string path = GetImagePath(car);
|
||||
// does image exist?
|
||||
if (System.IO.File.Exists(path))
|
||||
try
|
||||
{
|
||||
return Image.FromFile(path);
|
||||
if (System.IO.File.Exists(path))
|
||||
{
|
||||
return Image.FromFile(path);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Image.FromFile("images/no_image_available.png");
|
||||
Console.Error.WriteLine($"Error loading image: {ex.Message}");
|
||||
}
|
||||
|
||||
return Image.FromFile("images/no_image_available.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user