diff --git a/src/Magick.NET/MagickImage.cs b/src/Magick.NET/MagickImage.cs
index a0a0e37055..f024ae59fc 100644
--- a/src/Magick.NET/MagickImage.cs
+++ b/src/Magick.NET/MagickImage.cs
@@ -6012,7 +6012,12 @@ public void Shave(int size)
/// The number of pixels to shave top and bottom.
/// Thrown when an error is raised by ImageMagick.
public void Shave(int leftRight, int topBottom)
- => _nativeInstance.Shave(leftRight, topBottom);
+ {
+ Throw.IfNegative(nameof(leftRight), leftRight);
+ Throw.IfNegative(nameof(topBottom), topBottom);
+
+ _nativeInstance.Shave(leftRight, topBottom);
+ }
///
/// Shear image (create parallelogram by sliding image by X or Y axis).
diff --git a/tests/Magick.NET.Tests/MagickImageTests/TheShaveMethod.cs b/tests/Magick.NET.Tests/MagickImageTests/TheShaveMethod.cs
index 97e9b672a6..293900f5ce 100644
--- a/tests/Magick.NET.Tests/MagickImageTests/TheShaveMethod.cs
+++ b/tests/Magick.NET.Tests/MagickImageTests/TheShaveMethod.cs
@@ -1,6 +1,7 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.
+using System;
using ImageMagick;
using Xunit;
@@ -10,6 +11,30 @@ public partial class MagickImageTests
{
public class TheShaveMethod
{
+ [Fact]
+ public void ShouldThrowExceptionWhenSizeIsNegative()
+ {
+ using var image = new MagickImage();
+
+ Assert.Throws("leftRight", () => image.Shave(-1));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenLeftRightIsNegative()
+ {
+ using var image = new MagickImage();
+
+ Assert.Throws("leftRight", () => image.Shave(-1, 40));
+ }
+
+ [Fact]
+ public void ShouldThrowExceptionWhenTopBottomIsNegative()
+ {
+ using var image = new MagickImage();
+
+ Assert.Throws("topBottom", () => image.Shave(20, -1));
+ }
+
[Fact]
public void ShouldShaveSizeFromEdges()
{