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);
|
var result = SectionHeader.Parse(line);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
catch (Sprache.ParseException)
|
||||||
|
{
|
||||||
|
// Expected - line is not a section header, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
// Unexpected exception, return null to continue parsing
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,8 +135,14 @@ public static class EventOccurrenceGrammar
|
|||||||
GeneralSchedule.Parse(line);
|
GeneralSchedule.Parse(line);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (Sprache.ParseException)
|
||||||
|
{
|
||||||
|
// Expected - line is not a General Schedule header
|
||||||
|
return false;
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
// Unexpected exception, return false to continue parsing
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,8 +196,14 @@ public static class EventOccurrenceGrammar
|
|||||||
var parsed = result.Parse(restOfLine);
|
var parsed = result.Parse(restOfLine);
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
catch (Sprache.ParseException)
|
||||||
|
{
|
||||||
|
// Expected - line is not a valid occurrence line, return null
|
||||||
|
return null;
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
// Unexpected exception, return null to continue parsing
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user