1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

RGB Service - Catch & throw exceptions in a more controlled manner

This commit is contained in:
Robert 2021-04-26 17:12:23 +02:00
parent 77227b7e6e
commit ebfb82e323

View File

@ -148,8 +148,17 @@ namespace Artemis.Core.Services
foreach (ArtemisDevice device in toRemove)
RemoveDevice(device);
deviceProvider.Initialize(RGBDeviceType.All, true);
List<Exception> providerExceptions = new();
void DeviceProviderOnException(object? sender, Exception e) => providerExceptions.Add(e);
deviceProvider.Exception += DeviceProviderOnException;
deviceProvider.Initialize();
Surface.Attach(deviceProvider.Devices);
deviceProvider.Exception -= DeviceProviderOnException;
if (providerExceptions.Count == 1)
throw new ArtemisPluginException("RGB.NET threw exception: " + providerExceptions.First().Message, providerExceptions.First());
if (providerExceptions.Count > 1)
throw new ArtemisPluginException("RGB.NET threw multiple exceptions", new AggregateException(providerExceptions));
if (!deviceProvider.Devices.Any())
{