From 2b78d67046c9613bc871cabe6ba312455ba8e866 Mon Sep 17 00:00:00 2001 From: David K Date: Mon, 12 Feb 2024 15:38:20 +0000 Subject: [PATCH] #32 Exceptions added Should be easier to catch during testing now --- skullOS.Modules/Adventure.cs | 5 +++-- skullOS.Modules/Buzzer.cs | 5 +++-- skullOS.Modules/Exceptions/OnActionException.cs | 6 ++++++ skullOS.Modules/Exceptions/OnEnableException.cs | 6 ++++++ skullOS.Modules/Prop.cs | 5 +++-- skullOS.Modules/Support.cs | 5 +++-- 6 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 skullOS.Modules/Exceptions/OnActionException.cs create mode 100644 skullOS.Modules/Exceptions/OnEnableException.cs diff --git a/skullOS.Modules/Adventure.cs b/skullOS.Modules/Adventure.cs index 63008a9..333d3b1 100644 --- a/skullOS.Modules/Adventure.cs +++ b/skullOS.Modules/Adventure.cs @@ -1,6 +1,7 @@ using skullOS.Core; using skullOS.HardwareServices; using skullOS.HardwareServices.Interfaces; +using skullOS.Modules.Exceptions; using skullOS.Modules.Interfaces; using Timer = System.Timers.Timer; @@ -34,12 +35,12 @@ private void TakePicture_Elapsed(object? sender, System.Timers.ElapsedEventArgs public override void OnAction(object? sender, EventArgs e) { - throw new NotImplementedException(); + throw new OnActionException("Adventure does not support OnAction"); } public override void OnEnable(string[] args) { - throw new NotImplementedException(); + throw new OnEnableException("Adventure does not support OnEnable"); } public override string ToString() diff --git a/skullOS.Modules/Buzzer.cs b/skullOS.Modules/Buzzer.cs index 54f5412..a7e845e 100644 --- a/skullOS.Modules/Buzzer.cs +++ b/skullOS.Modules/Buzzer.cs @@ -1,4 +1,5 @@ using skullOS.HardwareServices; +using skullOS.Modules.Exceptions; using skullOS.Modules.Interfaces; using static skullOS.Modules.BuzzerLibrary; using static skullOS.Modules.BuzzerStructures; @@ -34,11 +35,11 @@ public void PlayTune(Tunes tuneToPlay) public override void OnAction(object? sender, EventArgs e) { - throw new NotImplementedException(); + throw new OnActionException("Buzzer does not support OnAction"); } public override void OnEnable(string[] args) { - throw new NotImplementedException(); + throw new OnEnableException("Buzzer does not support OnEnable"); } public override string ToString() { diff --git a/skullOS.Modules/Exceptions/OnActionException.cs b/skullOS.Modules/Exceptions/OnActionException.cs new file mode 100644 index 0000000..383164f --- /dev/null +++ b/skullOS.Modules/Exceptions/OnActionException.cs @@ -0,0 +1,6 @@ +namespace skullOS.Modules.Exceptions +{ + public class OnActionException(string message) : Exception(message) + { + } +} diff --git a/skullOS.Modules/Exceptions/OnEnableException.cs b/skullOS.Modules/Exceptions/OnEnableException.cs new file mode 100644 index 0000000..a70f3df --- /dev/null +++ b/skullOS.Modules/Exceptions/OnEnableException.cs @@ -0,0 +1,6 @@ +namespace skullOS.Modules.Exceptions +{ + public class OnEnableException(string message) : Exception(message) + { + } +} diff --git a/skullOS.Modules/Prop.cs b/skullOS.Modules/Prop.cs index e4788d2..02125d5 100644 --- a/skullOS.Modules/Prop.cs +++ b/skullOS.Modules/Prop.cs @@ -2,6 +2,7 @@ using skullOS.Core; using skullOS.HardwareServices; using skullOS.HardwareServices.Interfaces; +using skullOS.Modules.Exceptions; using System.Device.Pwm.Drivers; using Timer = System.Timers.Timer; @@ -102,12 +103,12 @@ private async void FlapEar(bool useLeft = true) public override void OnAction(object? sender, EventArgs e) { - throw new NotImplementedException(); + throw new OnActionException("Prop doesn't support OnAction"); } public override void OnEnable(string[] args) { - throw new NotImplementedException(); + throw new OnEnableException("Prop doesn't support OnEnable"); } public override string ToString() { diff --git a/skullOS.Modules/Support.cs b/skullOS.Modules/Support.cs index 527b629..1fbf99a 100644 --- a/skullOS.Modules/Support.cs +++ b/skullOS.Modules/Support.cs @@ -1,5 +1,6 @@ using skullOS.HardwareServices; using skullOS.HardwareServices.Interfaces; +using skullOS.Modules.Exceptions; using skullOS.Modules.Interfaces; using System.Device.Gpio; using Timer = System.Timers.Timer; @@ -42,12 +43,12 @@ private void LowBatteryAlert_Elapsed(object? sender, System.Timers.ElapsedEventA public override void OnAction(object? sender, EventArgs e) { - throw new NotImplementedException(); + throw new OnActionException("Support doesn't support OnAction"); } public override void OnEnable(string[] args) { - throw new NotImplementedException(); + throw new OnEnableException("Support doesn't support OnEnable"); } public override string ToString()