diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs index 27cd31fd85fa40..21047a98d7f6a9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonElement.cs @@ -473,12 +473,12 @@ public bool TryGetSByte(out sbyte value) [CLSCompliant(false)] public sbyte GetSByte() { - if (TryGetSByte(out sbyte value)) + if (!TryGetSByte(out sbyte value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -523,12 +523,12 @@ public bool TryGetByte(out byte value) /// public byte GetByte() { - if (TryGetByte(out byte value)) + if (!TryGetByte(out byte value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -570,12 +570,12 @@ public bool TryGetInt16(out short value) /// public short GetInt16() { - if (TryGetInt16(out short value)) + if (!TryGetInt16(out short value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } /// @@ -622,12 +622,12 @@ public bool TryGetUInt16(out ushort value) [CLSCompliant(false)] public ushort GetUInt16() { - if (TryGetUInt16(out ushort value)) + if (!TryGetUInt16(out ushort value)) { - return value; + ThrowHelper.ThrowFormatException(); } - throw new FormatException(); + return value; } ///