๐ WAYPOINT LESSON
Checkpoint โ Error handling
โญ beginnerโณ 20 min read๐ Lesson 53 of 85
A reservation service: layered validation, a custom exception with data, and a cleanup-guaranteed executor.
Checkpoint: the reservation service
Task: implement in Solution:
class BookingConflictException : Exceptionwithpublic string Slot { get; }(constructor(string slot, string message)โ base(message), store Slot).static string Book(List<string> takenSlots, string slot):- null/whitespace slot โ
ArgumentException; - slot already in
takenSlotsโBookingConflictException(Slot = slot); - otherwise add and return the slot.
- null/whitespace slot โ
static T Guard<T>(Func<T> action, string label):- runs
action; returns its result on success; - on exception: throws
InvalidOperationExceptionwith a message containinglabelโ but ONLY forInvalidOperationException; any other exception type must propagate unchanged; labelnull โArgumentExceptionbefore running action.
- runs