Skip to content

File tree

2 files changed

+60
-12
lines changed

2 files changed

+60
-12
lines changed

Cql/Cql.Runtime/Operators/CqlOperators.ArithmeticOperators.cs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,42 @@ internal partial class CqlOperators
5454
public int? Add(int? left, int? right)
5555
{
5656
if (left == null || right == null) return null;
57-
else return left + right;
57+
try
58+
{
59+
return left + right;
60+
}
61+
catch (OverflowException e)
62+
{
63+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Add", "Warning", "Ignored overflow errors from type integer addition, returned null.");
64+
return null;
65+
}
5866
}
5967

6068
public long? Add(long? left, long? right)
6169
{
6270
if (left == null || right == null) return null;
63-
else return left + right;
71+
try
72+
{
73+
return left + right;
74+
}
75+
catch (OverflowException e)
76+
{
77+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Add", "Warning", "Ignored overflow errors from type long addition, returned null.");
78+
return null;
79+
}
6480
}
6581
public decimal? Add(decimal? left, decimal? right)
6682
{
6783
if (left == null || right == null) return null;
68-
else return left + right;
84+
try
85+
{
86+
return left + right;
87+
}
88+
catch (OverflowException e)
89+
{
90+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Add", "Warning", "Ignored overflow errors from type decimal addition, returned null.");
91+
return null;
92+
}
6993
}
7094

7195
public CqlQuantity? Add(CqlQuantity? left, CqlQuantity? right)
@@ -674,18 +698,42 @@ internal partial class CqlOperators
674698
public int? Subtract(int? left, int? right)
675699
{
676700
if (left == null || right == null) return null;
677-
else return left - right;
701+
try
702+
{
703+
return left - right;
704+
}
705+
catch (OverflowException e)
706+
{
707+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Subtract", "Warning", "Ignored overflow errors from type integer subtraction, returned null.");
708+
return null;
709+
}
678710
}
679711

680712
public long? Subtract(long? left, long? right)
681713
{
682714
if (left == null || right == null) return null;
683-
else return left - right;
715+
try
716+
{
717+
return left - right;
718+
}
719+
catch (OverflowException e)
720+
{
721+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Subtract", "Warning", "Ignored overflow errors from type long subtraction, returned null.");
722+
return null;
723+
}
684724
}
685725
public decimal? Subtract(decimal? left, decimal? right)
686726
{
687727
if (left == null || right == null) return null;
688-
else return left - right;
728+
try
729+
{
730+
return left - right;
731+
}
732+
catch (OverflowException e)
733+
{
734+
Message(new { left, right, e }, "CqlOperators.ArithmeticOperators.Subtract", "Warning", "Ignored overflow errors from type decimal subtraction, returned null.");
735+
return null;
736+
}
689737
}
690738

691739
public CqlQuantity? Subtract(CqlQuantity? left, CqlQuantity? right)

Cql/Cql.Runtime/Operators/CqlOperators.DateTimeOperators.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal partial class CqlOperators
2727
}
2828
catch (ArgumentOutOfRangeException e)
2929
{
30-
Message(new { left, right, e }, "CqlOperators.Add", "Warning", "Ignored overflow errors from date addition, returned null.");
30+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Add", "Warning", "Ignored overflow errors from date addition, returned null.");
3131
return null;
3232
}
3333
}
@@ -41,7 +41,7 @@ internal partial class CqlOperators
4141
}
4242
catch (ArgumentOutOfRangeException e)
4343
{
44-
Message(new { left, right, e }, "CqlOperators.Add", "Warning", "Ignored overflow errors from datetime addition, returned null.");
44+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Add", "Warning", "Ignored overflow errors from datetime addition, returned null.");
4545
return null;
4646
}
4747
}
@@ -56,7 +56,7 @@ internal partial class CqlOperators
5656
}
5757
catch (ArgumentOutOfRangeException e)
5858
{
59-
Message(new { left, right, e }, "CqlOperators.Add", "Warning", "Ignored overflow errors from time addition, returned null.");
59+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Add", "Warning", "Ignored overflow errors from time addition, returned null.");
6060
return null;
6161
}
6262
}
@@ -351,7 +351,7 @@ internal partial class CqlOperators
351351
}
352352
catch (ArgumentOutOfRangeException e)
353353
{
354-
Message(new { left, right, e }, "CqlOperators.Subtract", "Warning", "Ignored overflow errors from date subtraction, returned null.");
354+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Subtract", "Warning", "Ignored overflow errors from date subtraction, returned null.");
355355
return null;
356356
}
357357
}
@@ -366,7 +366,7 @@ internal partial class CqlOperators
366366
}
367367
catch (ArgumentOutOfRangeException e)
368368
{
369-
Message(new { left, right, e }, "CqlOperators.Subtract", "Warning", "Ignored overflow errors from datetime subtraction, returned null.");
369+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Subtract", "Warning", "Ignored overflow errors from datetime subtraction, returned null.");
370370
return null;
371371
}
372372
}
@@ -381,7 +381,7 @@ internal partial class CqlOperators
381381
}
382382
catch (ArgumentOutOfRangeException e)
383383
{
384-
Message(new { left, right, e }, "CqlOperators.Subtract", "Warning", "Ignored overflow errors from time subtraction, returned null.");
384+
Message(new { left, right, e }, "CqlOperators.DateTimeOperators.Subtract", "Warning", "Ignored overflow errors from time subtraction, returned null.");
385385
return null;
386386
}
387387
}

0 commit comments

Comments
 (0)