Skip to content

Commit

Permalink
add exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Milkitic committed Feb 8, 2022
1 parent a7e4286 commit 7c0eb77
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/KbinXml.Net/KbinConverter.Writers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,22 @@ void EnsureHolding()
int i = 0;
foreach (var s in value)
{
if (i == iSize) break;
var add = type.WriteString(ref builder, s);
if (add < type.Size)
try
{
var left = type.Size - add;
for (var j = 0; j < left; j++) builder.Append(0);
if (i == iSize) break;
var add = type.WriteString(ref builder, s);
if (add < type.Size)
{
var left = type.Size - add;
for (var j = 0; j < left; j++) builder.Append(0);
}

i += type.Size;
}
catch (Exception e)
{
throw new KbinException($"Error while writing data '{s.ToString()}'. See InnerException for more information.", e);
}

i += type.Size;
}

context.DataWriter.WriteBytes(builder.AsSpan());
Expand Down
5 changes: 5 additions & 0 deletions src/KbinXml.Net/KbinException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public KbinException(string message) : base(message)
{

}

public KbinException(string message, Exception? innerException) : base(message, innerException)
{

}
}

0 comments on commit 7c0eb77

Please sign in to comment.