#25: use MissingTableException instead of default exception

pull/27/head
Simon G 5 years ago
parent 7ab02d7d3a
commit 92c278319e
  1. 13
      GBase/Exceptions/MissingTableException.cs
  2. 7
      GBase/GBase.cs
  3. 4
      GBase/GBaseObject.cs

@ -9,20 +9,15 @@ namespace GBase.Exceptions
/// <summary> /// <summary>
/// <see cref="Exception"/> that the table for the given <see cref="Type"/> is missing /// <see cref="Exception"/> that the table for the given <see cref="Type"/> is missing
/// </summary> /// </summary>
public class MissingTableException : Exception public class MissingTableException<T> : Exception
{ {
/// <summary> /// <summary>
/// <see cref="Exception"/> that the table for the given <see cref="Type"/> is missing /// <see cref="Exception"/> that the table for the given <see cref="Type"/> is missing
/// </summary> /// </summary>
public MissingTableException(Type type) public MissingTableException()
: base($"There is no table for type {type}.") : base($"There is no table for type {typeof(T)}.")
{ {
Type = type;
}
/// <summary> }
/// The <see cref="Type"/> that has no table
/// </summary>
public Type Type { get; }
} }
} }

@ -9,6 +9,7 @@ using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Attributes; using GBase.Attributes;
using GBase.Exceptions;
using GBase.Factories; using GBase.Factories;
using GBase.Interfaces; using GBase.Interfaces;
using GBase.Interfaces.Settings; using GBase.Interfaces.Settings;
@ -121,7 +122,7 @@ namespace GBase
{ {
IGBaseTable<T> table = GetTable<T>(); IGBaseTable<T> table = GetTable<T>();
if (table == null) if (table == null)
throw new Exception(); //TODO: Create exception throw new MissingTableException<T>();
return await table.AddEntry(entry, cancellationToken); return await table.AddEntry(entry, cancellationToken);
} }
@ -130,7 +131,7 @@ namespace GBase
{ {
IGBaseTable<T> table = GetTable<T>(); IGBaseTable<T> table = GetTable<T>();
if (table == null) if (table == null)
throw new Exception(); //TODO: Create exception throw new MissingTableException<T>();
await table.SetValue(entry, propertyName, value, cancellationToken); await table.SetValue(entry, propertyName, value, cancellationToken);
} }
@ -139,7 +140,7 @@ namespace GBase
{ {
IGBaseTable<T> table = GetTable<T>(); IGBaseTable<T> table = GetTable<T>();
if (table == null) if (table == null)
throw new Exception(); //TODO: Create exception throw new MissingTableException<T>();
return await table.GetValue<TProperty>(entry, propertyName, cancellationToken); return await table.GetValue<TProperty>(entry, propertyName, cancellationToken);
} }

@ -20,12 +20,12 @@ namespace GBase
/// <summary> /// <summary>
/// GBase object that allows conversion from <see cref="string"/> /// GBase object that allows conversion from <see cref="string"/>
/// </summary> /// </summary>
/// <exception cref="MissingTableException">No table for <typeparamref name="T"/> is existing</exception> /// <exception cref="MissingTableException{T}">No table for <typeparamref name="T"/> is existing</exception>
protected GBaseObject(IGBase gBase) protected GBaseObject(IGBase gBase)
{ {
_gBaseTable = gBase.GetTable<T>(); _gBaseTable = gBase.GetTable<T>();
if (_gBaseTable == null) if (_gBaseTable == null)
throw new MissingTableException(typeof(T)); throw new MissingTableException<T>();
} }

Loading…
Cancel
Save