improve error message for TargetParameterCountException in the reflection API

This commit is contained in:
Jesse Plamondon-Willard 2019-12-15 00:33:08 -05:00
parent 18a5b07c5b
commit d662ea858c
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 5 additions and 0 deletions

View File

@ -11,6 +11,7 @@
* For modders: * For modders:
* Added asset propagation for grass textures. * Added asset propagation for grass textures.
* Added asset propagation for `Data\Bundles` changes (for added bundles only). * Added asset propagation for `Data\Bundles` changes (for added bundles only).
* Improved error messages for `TargetParameterCountException` when using the reflection API.
* `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event). * `helper.Read/WriteSaveData` can now be used while a save is being loaded (e.g. within a `Specialized.LoadStageChanged` event).
* Fixed private textures loaded from content packs not having their `Name` field set. * Fixed private textures loaded from content packs not having their `Name` field set.

View File

@ -65,6 +65,10 @@ namespace StardewModdingAPI.Framework.Reflection
{ {
result = this.MethodInfo.Invoke(this.Parent, arguments); result = this.MethodInfo.Invoke(this.Parent, arguments);
} }
catch (TargetParameterCountException)
{
throw new Exception($"Couldn't invoke the {this.DisplayName} method: it expects {this.MethodInfo.GetParameters().Length} parameters, but {arguments.Length} were provided.");
}
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception($"Couldn't invoke the {this.DisplayName} method", ex); throw new Exception($"Couldn't invoke the {this.DisplayName} method", ex);