...
Code Block | ||
---|---|---|
| ||
double currentBalance; // User's cash balance void doDeposit(String s){ double val; try { val = Double.valueOf(userInput); } catch (NumberFormatException e) { // Handle input format error } if (Double.isInfinite(val)){ // Handle infinity error } if (Double.isNaN(val)) { // Handle NaN error } if (val >= Double.MAX_VALUE - currentBalance) { // Handle range error } currentBalance += val; } |
Exceptions
NUM08-EX0: Occasionally, NaN
, infinity
, or -infinity
may be acceptable as expected inputs to a program. In such cases, explicit checks might not be necessary. However, such programs must be prepared to handle these exceptional values gracefully and should prevent propagation of the exceptional values to other code that fails to handle exceptional values. The choice to permit input of exceptional values during ordinary operation should be explicitly documented.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5b581df6ac40d4ea-8a1ee83a-40834f2e-892e862b-88daa5a16ae62c937eea9316"><ac:plain-text-body><![CDATA[ | [[IEEE 754 | https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-IEEE7542006 | IEEE 754]] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="63ec4bf96c0e0c5c-b7822444-402c4173-a259a376-932bd378e2d75d4bfa52e589"><ac:plain-text-body><![CDATA[ | [[IEEE 1003.1, 2004 | https://www.securecoding.cert.org/confluence/display/seccode/AA.+C+References#AA.CReferences-IEEE1003 | IEEE 1003.1, 2004]] | ]]></ac:plain-text-body></ac:structured-macro> |
...