Skip to content

Commit 4edd203

Browse files
Fix ArgumentException when FontName in setting file is not valid
Fixes #468
1 parent 0c1ed7f commit 4edd203

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/LogExpert.UI/Controls/LogWindow/LogWindow.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7179,7 +7179,20 @@ public void PreferencesChanged (string fontName, float fontSize, bool setLastCol
71797179
{
71807180
if ((flags & SettingsFlags.GuiOrColors) == SettingsFlags.GuiOrColors)
71817181
{
7182-
NormalFont = new Font(new FontFamily(fontName), fontSize);
7182+
Font NormalFont;
7183+
7184+
try
7185+
{
7186+
NormalFont = new Font(new FontFamily(fontName), fontSize);
7187+
}
7188+
catch (ArgumentException ex)
7189+
{
7190+
_logger.Warn($"Specified font '{fontName}' not found. Falling back to default. {ex.Message}");
7191+
// NOTE: Checking for invalid font name and falling back to default font might belong in LogExpert.Config.ConfigManager
7192+
NormalFont = new Font(FontFamily.GenericMonospace, fontSize);
7193+
Preferences.FontName = NormalFont.Name;
7194+
}
7195+
71837196
BoldFont = new Font(NormalFont, FontStyle.Bold);
71847197
MonospacedFont = new Font("Courier New", Preferences.FontSize, FontStyle.Bold);
71857198

0 commit comments

Comments
 (0)