From c4e7edf3db7857acf4b49c7d8d7f9fd9b517f578 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Fri, 9 Jan 2026 10:50:18 -0500 Subject: [PATCH] Improve error handling in EventOccurrenceGrammar parsing methods This commit enhances the error handling in the EventOccurrenceGrammar class by adding specific catch blocks for expected parse exceptions. Each parsing method now gracefully returns null or false when encountering a known parse exception, while still handling unexpected exceptions to ensure the parsing process continues smoothly. This change improves the robustness and clarity of the parsing logic. --- Core/Parsers/EventOccurrenceGrammar.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Core/Parsers/EventOccurrenceGrammar.cs b/Core/Parsers/EventOccurrenceGrammar.cs index 7755aa7..81ef9c0 100644 --- a/Core/Parsers/EventOccurrenceGrammar.cs +++ b/Core/Parsers/EventOccurrenceGrammar.cs @@ -112,8 +112,14 @@ public static class EventOccurrenceGrammar var result = SectionHeader.Parse(line); return result; } + catch (Sprache.ParseException) + { + // Expected - line is not a section header, return null + return null; + } catch { + // Unexpected exception, return null to continue parsing return null; } } @@ -129,8 +135,14 @@ public static class EventOccurrenceGrammar GeneralSchedule.Parse(line); return true; } + catch (Sprache.ParseException) + { + // Expected - line is not a General Schedule header + return false; + } catch { + // Unexpected exception, return false to continue parsing return false; } } @@ -184,8 +196,14 @@ public static class EventOccurrenceGrammar var parsed = result.Parse(restOfLine); return parsed; } + catch (Sprache.ParseException) + { + // Expected - line is not a valid occurrence line, return null + return null; + } catch { + // Unexpected exception, return null to continue parsing return null; } }