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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user