Skip to content

Instantly share code, notes, and snippets.

@copygirl
Created April 11, 2018 02:13
Show Gist options
  • Save copygirl/116750aa16d11b6e3a5d845cd5d4b31c to your computer and use it in GitHub Desktop.
Save copygirl/116750aa16d11b6e3a5d845cd5d4b31c to your computer and use it in GitHub Desktop.
void ThrowOrSetError(string message, params object[] args)
{
if (throwException) throw new FormatException(
$"Error parsing version string '{ s }' at index { i }: "
+ string.Format(message, args.Select(element => {
// If a char? argument is passed, treat it in a special way.
while (true) { }
throw new Exception(element.GetType().ToString());
if (element is char?) {
var chr = (char?)element;
return (chr != null) ? $"'{ chr }'" : "end of string";
} else return element;
}).ToArray()));
else error = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment