Index: Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs
===================================================================
diff -u -rf67ccd7b88da303d2ac322bbd489f2c6ea287e1c -r97c9e382dffcf32dc34d2e05e6a8a475b833ebd4
--- Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision f67ccd7b88da303d2ac322bbd489f2c6ea287e1c)
+++ Ringtoets/Piping/src/Ringtoets.Piping.IO/PipingSoilProfileReader.cs (.../PipingSoilProfileReader.cs) (revision 97c9e382dffcf32dc34d2e05e6a8a475b833ebd4)
@@ -126,35 +126,64 @@
///
/// A new with information from the database.
/// Thrown when a layer's geometry could not be parsed as XML.
+ /// Thrown when no valid point to obtain a one-dimensional
+ /// intersection from was read from the database, or when after reading layers, no layers were added
+ /// to be build.
private PipingSoilProfile ReadPipingProfile2D()
{
var profileName = TryRead(profileNameColumn);
var layerCount = TryRead(layerCountColumn);
var intersectionX = TryRead(intersectionXColumn);
- var soilProfileBuilder = new SoilProfileBuilder2D(profileName, intersectionX);
-
- for (int i = 1; i <= layerCount; i++)
+ try
{
- try
+ var soilProfileBuilder = new SoilProfileBuilder2D(profileName, intersectionX);
+
+ for (int i = 1; i <= layerCount; i++)
{
- soilProfileBuilder.Add(ReadPiping2DSoilLayer());
+ try
+ {
+ soilProfileBuilder.Add(ReadPiping2DSoilLayer());
+ }
+ catch (SoilLayer2DConversionException e)
+ {
+ HandleLayerParseException(layerCount, i, profileName, e);
+ }
+ catch (XmlException e)
+ {
+ HandleLayerParseException(layerCount, i, profileName, e);
+ }
+ MoveNext();
}
- catch (XmlException e)
- {
- var exception = new PipingSoilProfileReadException(
- string.Format(Resources.PipingSoilProfileReader_CouldNotParseGeometryOfLayer_0_InProfile_1_, i, profileName), e);
- SkipRecords((int)layerCount + 1 - i);
-
- throw exception;
- }
- MoveNext();
+ return soilProfileBuilder.Build();
}
+ catch (ArgumentException e)
+ {
+ HandleCriticalBuildException(profileName, e);
+ }
+ catch (SoilProfileBuilderException e)
+ {
+ HandleCriticalBuildException(profileName, e);
+ }
+ return null;
+ }
- return soilProfileBuilder.Build();
+ private static void HandleCriticalBuildException(string profileName, Exception e)
+ {
+ var message = string.Format(Resources.PipingSoilProfileReader_Could_not_build_profile_0_from_layer_definitions, profileName);
+ throw new CriticalFileReadException(message, e);
}
+ private void HandleLayerParseException(long layerCount, int i, string profileName, Exception e)
+ {
+ SkipRecords((int) layerCount + 1 - i);
+ var exception = new PipingSoilProfileReadException(
+ string.Format(Resources.PipingSoilProfileReader_CouldNotParseGeometryOfLayer_0_InProfile_1_, i, profileName), e);
+
+ throw exception;
+ }
+
private void SkipRecords(int count)
{
for(int i = 0; i < count; i++)