How can I check if a Uri
(file) exists in a referenced project?
Per this answer I've tried catching a FileNotFound
exception but it isn't throwing any exceptions at all
string x;
try {
var Uri = new Uri("/FamFamFam.Flags.Wpf;component/Images/some_wrong_file.png",
UriKind.Relative);
x = "a";
}
catch(Exception) {
x = "b";
}
MessageBox.Show(x);
Per an MSDN thread, I've tried checking if the resultant Bitmap
is null, but it always shows 'a':
string x;
try {
var Bitmap = new BitmapImage(new Uri(
"/FamFamFam.Flags.Wpf;component/Images/some_wrong_file.png", UriKind.Relative));
Flag_Image.Source = Bitmap ?? throw new Exception();
x = "a";
}
catch(Exception) {
Flag_Image.Source = new BitmapImage(new Uri(
"/FamFamFam.Flags.Wpf;component/Images/ca.png", UriKind.Relative));
x = "b";
}
MessageBox.Show(x);