catch exceptions

This commit is contained in:
Philip Schell 2019-11-29 14:46:10 +01:00
parent cc00efe5ea
commit 7ee7060c7c
2 changed files with 9 additions and 8 deletions

View File

@ -22,18 +22,20 @@ namespace BlubbFish.Utils.IoT.Connector {
if (settings.Count == 0) { if (settings.Count == 0) {
return null; return null;
} }
String object_sensor = "BlubbFish.Utils.IoT.Connector." + ty.ToString() + "." + settings["type"].ToUpperLower() + ", " + "Connector" + ty.ToString() + settings["type"].ToUpperLower(); String object_sensor = "BlubbFish.Utils.IoT.Connector." + ty.ToString() + "." + settings["type"].ToUpperLower() + ", " + "Connector" + ty.ToString() + settings["type"].ToUpperLower();
Type t;
try { try {
t = Type.GetType(object_sensor, true); Type t = Type.GetType(object_sensor, true);
return (ABackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
} catch (TypeLoadException) { } catch (TypeLoadException) {
Console.Error.WriteLine("Configuration: " + settings["type"] + " is not a " + ty.ToString() + "Backend"); Console.Error.WriteLine("Configuration: " + settings["type"] + " is not a " + ty.ToString() + "Backend");
return null; return null;
} catch (System.IO.FileNotFoundException) { } catch (System.IO.FileNotFoundException) {
Console.Error.WriteLine("Driver " + object_sensor + " could not load!"); Console.Error.WriteLine("Driver " + object_sensor + " could not load!");
return null; return null;
} catch (Exception e) {
Console.Error.WriteLine("Something bad Happend while Loading Connectior: "+e.Message);
} }
return (ABackend)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings }); return null;
} }
protected void NotifyClientIncomming(BackendEvent value) => this.MessageIncomming?.Invoke(this, value); protected void NotifyClientIncomming(BackendEvent value) => this.MessageIncomming?.Invoke(this, value);

View File

@ -1,12 +1,11 @@
using System.Reflection; #if !NETCOREAPP
using System.Reflection;
using System.Resources; using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
#if NETCOREAPP
#else
[assembly: AssemblyTitle("Utils-IoT")] [assembly: AssemblyTitle("Utils-IoT")]
[assembly: AssemblyDescription("Provides classes for iot development")] [assembly: AssemblyDescription("Provides classes for iot development")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]