Skip to content

Commit

Permalink
Add More specific exception for data record
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtule committed May 30, 2017
1 parent 576bedf commit 2a00246
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
16 changes: 16 additions & 0 deletions DotNetDBF/DBFException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ public DBTException(String msg, Exception internalException)
{
}
}

public class DBFRecordException : DBFException
{
public int Record { get; }

public DBFRecordException(String msg, int record) : base(msg)
{
Record = record;
}

public DBFRecordException(String msg, Exception internalException)
: base(msg, internalException)
{
}
}

public class DBFException : IOException
{
public DBFException() : base()
Expand Down
18 changes: 6 additions & 12 deletions DotNetDBF/DBFWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,47 +260,41 @@ private void AddRecord(Object[] values, bool writeImediately)
case NativeDbType.Char:
if (!(values[i] is String) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;

case NativeDbType.Logical:
if (!(values[i] is Boolean) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;

case NativeDbType.Numeric:
if (!(values[i] is IConvertible) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;

case NativeDbType.Date:
if (!(values[i] is DateTime) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;

case NativeDbType.Float:
if (!(values[i] is IConvertible) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;
case NativeDbType.Memo:
if (!(values[i] is MemoValue) && !(values[i] is DBNull))
{
throw new DBFException("Invalid value for field "
+ i);
throw new DBFRecordException($"Invalid value for field {i}", i);
}
break;
}
Expand Down
6 changes: 3 additions & 3 deletions DotNetDBF/DotNetDBF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<TargetFrameworks>net35;netstandard1.3</TargetFrameworks>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>sn.snk</AssemblyOriginatorKeyFile>
<Version>5.0.2.0</Version>
<AssemblyVersion>5.0.2.0</AssemblyVersion>
<FileVersion>5.0.2.0</FileVersion>
<Version>5.0.3.0</Version>
<AssemblyVersion>5.0.3.0</AssemblyVersion>
<FileVersion>5.0.3.0</FileVersion>
<Company>Ekon Benefits</Company>
<Copyright>Copyright 2009-2017</Copyright>
<Description>This is a basic file parser for reading and writing xBase DBF files particularlly Clipper. Code originally derived from javadbf.</Description>
Expand Down

0 comments on commit 2a00246

Please sign in to comment.