如何检查引用的项目中是否存在Uri
(文件)?
每this answer我都试图捕获一个FileNotFound
异常,但它根本没有引发任何异常
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);
对于每个an MSDN thread,我尝试检查结果Bitmap
是否为空,但始终显示'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);