From 7c0eb7736d7b1093432ca67138183db0d188c590 Mon Sep 17 00:00:00 2001 From: Milkitic Date: Tue, 8 Feb 2022 10:25:29 +0800 Subject: [PATCH] add exception --- src/KbinXml.Net/KbinConverter.Writers.cs | 21 ++++++++++++++------- src/KbinXml.Net/KbinException.cs | 5 +++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/KbinXml.Net/KbinConverter.Writers.cs b/src/KbinXml.Net/KbinConverter.Writers.cs index 20a3dd5..143b6c0 100644 --- a/src/KbinXml.Net/KbinConverter.Writers.cs +++ b/src/KbinXml.Net/KbinConverter.Writers.cs @@ -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()); diff --git a/src/KbinXml.Net/KbinException.cs b/src/KbinXml.Net/KbinException.cs index 1a1ab32..519c145 100644 --- a/src/KbinXml.Net/KbinException.cs +++ b/src/KbinXml.Net/KbinException.cs @@ -16,4 +16,9 @@ public KbinException(string message) : base(message) { } + + public KbinException(string message, Exception? innerException) : base(message, innerException) + { + + } } \ No newline at end of file