change throw to return and fix bug: when error always throw
This commit is contained in:
@@ -18,10 +18,10 @@ namespace Common
|
||||
{
|
||||
if (length > 8)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
return new(new ArgumentException(
|
||||
"Unsigned long number can't over 8 bytes(64 bits).",
|
||||
nameof(length)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
var arr = new byte[length];
|
||||
@@ -53,10 +53,10 @@ namespace Common
|
||||
{
|
||||
if (bytes.Length > 8)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
return new(new ArgumentException(
|
||||
"Unsigned long number can't over 8 bytes(64 bits).",
|
||||
nameof(bytes)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
ulong num = 0;
|
||||
@@ -106,7 +106,7 @@ namespace Common
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public static Result<ulong> MultiBitsToNumber(ulong bits1, uint bits1Len, ulong bits2, uint bits2Len)
|
||||
{
|
||||
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
|
||||
if (bits1Len + bits2Len > 64) return new(new ArgumentException("Two Bits is more than 64 bits"));
|
||||
|
||||
ulong num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
|
||||
return num;
|
||||
@@ -122,7 +122,7 @@ namespace Common
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public static Result<uint> MultiBitsToNumber(uint bits1, uint bits1Len, uint bits2, uint bits2Len)
|
||||
{
|
||||
if (bits1Len + bits2Len > 64) throw new ArgumentException("Two Bits is more than 64 bits");
|
||||
if (bits1Len + bits2Len > 64) return new(new ArgumentException("Two Bits is more than 64 bits"));
|
||||
|
||||
uint num = (bits1 << Convert.ToInt32(bits2Len)) | bits2;
|
||||
return num;
|
||||
|
||||
Reference in New Issue
Block a user