Add exception handler

This commit is contained in:
Jack251970 2025-04-01 20:54:36 +08:00
parent 482fdc939f
commit 35ea1e33a9
2 changed files with 20 additions and 4 deletions

View file

@ -327,6 +327,7 @@
<system:String x:Key="clearlogfolderMessage">Are you sure you want to delete all logs?</system:String>
<system:String x:Key="clearcachefolder">Clear Caches</system:String>
<system:String x:Key="clearcachefolderMessage">Are you sure you want to delete all caches?</system:String>
<system:String x:Key="clearfolderfailMessage">Failed to clear folders and files</system:String>
<system:String x:Key="welcomewindow">Wizard</system:String>
<system:String x:Key="userdatapath">User Data Location</system:String>
<system:String x:Key="userdatapathToolTip">User settings and installed plugins are saved in the user data folder. This location may vary depending on whether it's in portable mode or not.</system:String>

View file

@ -103,7 +103,15 @@ public partial class SettingsPaneAboutViewModel : BaseModel
if (confirmResult == MessageBoxResult.Yes)
{
ClearLogFolder();
try
{
ClearLogFolder();
}
catch (Exception e)
{
App.API.LogException(nameof(SettingsPaneAboutViewModel), "Failed to clear log folder", e);
App.API.ShowMsgBox(App.API.GetTranslation("clearfolderfailMessage"));
}
}
}
@ -118,7 +126,15 @@ public partial class SettingsPaneAboutViewModel : BaseModel
if (confirmResult == MessageBoxResult.Yes)
{
ClearCacheFolder();
try
{
ClearCacheFolder();
}
catch (Exception e)
{
App.API.LogException(nameof(SettingsPaneAboutViewModel), "Failed to clear cache folder", e);
App.API.ShowMsgBox(App.API.GetTranslation("clearfolderfailMessage"));
}
}
}
@ -202,8 +218,7 @@ public partial class SettingsPaneAboutViewModel : BaseModel
foreach (string order in orders)
{
if (bytes > max)
return $"{decimal.Divide(bytes, max):##.##} {order}";
if (bytes > max) return $"{decimal.Divide(bytes, max):##.##} {order}";
max /= scale;
}