Skip to content

Commit

Permalink
Fix: Handle format exception raised by Convert.ToInt32 (#13749)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragoni7 committed Nov 8, 2023
1 parent e52b242 commit f4ab096
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Files.App/ViewModels/Properties/Items/FileProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private IValueConverter GetConverter()
/// Converts the property to a string to be displayed
/// </summary>
/// <returns></returns>
private string ConvertToString()
private string? ConvertToString()
{
// Don't attempt any convert null values
if (Value is null)
Expand All @@ -227,13 +227,27 @@ private string ConvertToString()

if (EnumeratedList is not null)
{
var value = "";
return EnumeratedList.TryGetValue(Convert.ToInt32(Value), out value) ? value.GetLocalizedResource() : null;
try
{
return EnumeratedList.TryGetValue(Convert.ToInt32(Value), out var value) ?
value.GetLocalizedResource() : null;
}
catch
{
return null;
}
}

if (DisplayFunction is not null)
{
return DisplayFunction.Invoke(Value);
try
{
return DisplayFunction.Invoke(Value);
}
catch
{
return null;
}
}

if (Converter is not null)
Expand Down

0 comments on commit f4ab096

Please sign in to comment.