From f10ee2873c1f4b9a5adcd4ecf6e49c9608b9dbab Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Thu, 7 Jul 2022 18:30:53 +0200
Subject: [PATCH] AbstractXMLType: Throw meaningful error message on access to
 Null-References.

---
 .../InputData/FileIO/XML/Common/AbstractXMLType.cs  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs b/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs
index a4c38f960e..aaf93c05a5 100644
--- a/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs
+++ b/VectoCore/VectoCore/InputData/FileIO/XML/Common/AbstractXMLType.cs
@@ -29,6 +29,7 @@
 *   Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
 */
 
+using System;
 using System.Collections.Generic;
 using System.Xml;
 using TUGraz.VectoCommon.Exceptions;
@@ -136,12 +137,14 @@ namespace TUGraz.VectoCore.InputData.FileIO.XML.Common {
 
 		protected virtual TableData ReadTableData(string baseElement, string entryElement, Dictionary<string, string> mapping)
 		{
-			var entries = BaseNode.SelectNodes(
-				XMLHelper.QueryLocalName(baseElement, entryElement));
-			if (entries != null && entries.Count > 0) {
-				return XMLHelper.ReadTableData(mapping, entries);
+			try {
+				var entries = BaseNode.SelectNodes(XMLHelper.QueryLocalName(baseElement, entryElement));
+				if (entries != null && entries.Count > 0) {
+					return XMLHelper.ReadTableData(mapping, entries);
+				}
+			} catch (NullReferenceException) {
+				throw new VectoException($"Could not find element: {baseElement} {entryElement}");
 			}
-
 			return null;
 		}
 	}
-- 
GitLab