Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/09 14:22:29 (16 years ago)
Author:
epitzer
Message:

Added PersistenceException used consistently for all error conditions in the persistence framework (#548)

Location:
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleArray2XmlFormatters.cs

    r1612 r1625  
    22using HeuristicLab.Persistence.Core;
    33using System.Globalization;
     4using HeuristicLab.Persistence.Default.Decomposers.Storable;
    45
    56namespace HeuristicLab.Persistence.Default.Xml.Compact {
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntArray2XmlFormatters.cs

    r1612 r1625  
    11using System;
    22using HeuristicLab.Persistence.Core;
     3using HeuristicLab.Persistence.Default.Decomposers.Storable;
    34
    45namespace HeuristicLab.Persistence.Default.Xml.Compact {
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlFormatterBase.cs

    r1612 r1625  
    33using HeuristicLab.Persistence.Interfaces;
    44using System;
     5using HeuristicLab.Persistence.Core;
    56
    67namespace HeuristicLab.Persistence.Default.Xml.Compact {
     
    4647
    4748    public override T Parse(XmlString x) {
    48       IEnumerator values =
    49         x.Data.Split(new[] { Separator },
    50         StringSplitOptions.RemoveEmptyEntries).GetEnumerator();
    51       values.MoveNext();
    52       int rank = int.Parse((string)values.Current);
    53       int[] lengths = new int[rank];
    54       for (int i = 0; i < rank; i++) {
     49      try {
     50        IEnumerator values =
     51          x.Data.Split(new[] { Separator },
     52          StringSplitOptions.RemoveEmptyEntries).GetEnumerator();
    5553        values.MoveNext();
    56         lengths[i] = int.Parse((string)values.Current);
    57       }
    58       int[] lowerBounds = new int[rank];
    59       for (int i = 0; i < rank; i++) {
    60         values.MoveNext();
    61         lowerBounds[i] = int.Parse((string)values.Current);
    62       }
    63       Array a = Array.CreateInstance(this.SourceType.GetElementType(), lengths, lowerBounds);
    64       int[] positions = new int[rank];
    65       while (values.MoveNext()) {
    66         a.SetValue(ParseValue((string)values.Current), positions);
    67         positions[0] += 1;
    68         for (int i = 0; i < rank - 1; i++) {
    69           if (positions[i] >= lengths[i]) {
    70             positions[i] = 0;
    71             positions[i + 1] += 1;
    72           } else {
    73             break;
     54        int rank = int.Parse((string)values.Current);
     55        int[] lengths = new int[rank];
     56        for (int i = 0; i < rank; i++) {
     57          values.MoveNext();
     58          lengths[i] = int.Parse((string)values.Current);
     59        }
     60        int[] lowerBounds = new int[rank];
     61        for (int i = 0; i < rank; i++) {
     62          values.MoveNext();
     63          lowerBounds[i] = int.Parse((string)values.Current);
     64        }
     65        Array a = Array.CreateInstance(this.SourceType.GetElementType(), lengths, lowerBounds);
     66        int[] positions = (int[])lowerBounds.Clone();
     67        while (values.MoveNext()) {
     68          a.SetValue(ParseValue((string)values.Current), positions);
     69          positions[0] += 1;
     70          for (int i = 0; i < rank - 1; i++) {
     71            if (positions[i] >= lengths[i]) {
     72              positions[i] = 0;
     73              positions[i + 1] += 1;
     74            } else {
     75              break;
     76            }
    7477          }
    7578        }
    76       }     
    77       return (T)(object)a;
     79        if (positions[rank - 1] != lowerBounds[rank - 1] + lengths[rank - 1])
     80          throw new PersistenceException("Insufficient number of elements while trying to fill number array.");
     81        return (T)(object)a;
     82      } catch (InvalidOperationException e) {
     83        throw new PersistenceException("Insufficient information to rebuild number array.", e);
     84      } catch (InvalidCastException e) {
     85        throw new PersistenceException("Invalid element data or meta data to reconstruct number array.", e);
     86      } catch (OverflowException e) {
     87        throw new PersistenceException("Overflow during element parsing while trying to reconstruct number array.", e);
     88      }
    7889    }
    7990  }
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlFormatterBase.cs

    r1566 r1625  
    33using HeuristicLab.Persistence.Interfaces;
    44using System;
     5using HeuristicLab.Persistence.Core;
    56
    67namespace HeuristicLab.Persistence.Default.Xml.Compact {
     
    2425
    2526    public override T Parse(XmlString x) {
    26       IEnumerable enumeration = Instantiate();
    27       string[] values = x.Data.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
    28       foreach (var value in values) {
    29         Add(enumeration, ParseValue(value));
    30       }
    31       return (T)enumeration;
     27      try {
     28        IEnumerable enumeration = Instantiate();
     29        string[] values = x.Data.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
     30        foreach (var value in values) {
     31          Add(enumeration, ParseValue(value));
     32        }
     33        return (T)enumeration;
     34      } catch (InvalidCastException e) {
     35        throw new PersistenceException("Invalid element data during reconstruction of number enumerable.", e);
     36      } catch (OverflowException e) {
     37        throw new PersistenceException("Overflow during element parsing while trying to reconstruct number enumerable.", e);
     38      }       
    3239    }
    3340  }
Note: See TracChangeset for help on using the changeset viewer.