Skip to content

Commit f4ab096

Browse files
authored
Fix: Handle format exception raised by Convert.ToInt32 (#13749)
1 parent e52b242 commit f4ab096

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Files.App/ViewModels/Properties/Items/FileProperty.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private IValueConverter GetConverter()
217217
/// Converts the property to a string to be displayed
218218
/// </summary>
219219
/// <returns></returns>
220-
private string ConvertToString()
220+
private string? ConvertToString()
221221
{
222222
// Don't attempt any convert null values
223223
if (Value is null)
@@ -227,13 +227,27 @@ private string ConvertToString()
227227

228228
if (EnumeratedList is not null)
229229
{
230-
var value = "";
231-
return EnumeratedList.TryGetValue(Convert.ToInt32(Value), out value) ? value.GetLocalizedResource() : null;
230+
try
231+
{
232+
return EnumeratedList.TryGetValue(Convert.ToInt32(Value), out var value) ?
233+
value.GetLocalizedResource() : null;
234+
}
235+
catch
236+
{
237+
return null;
238+
}
232239
}
233240

234241
if (DisplayFunction is not null)
235242
{
236-
return DisplayFunction.Invoke(Value);
243+
try
244+
{
245+
return DisplayFunction.Invoke(Value);
246+
}
247+
catch
248+
{
249+
return null;
250+
}
237251
}
238252

239253
if (Converter is not null)

0 commit comments

Comments
 (0)