{"record":{"id":"c6b491a86d7cd4c3","repo":"TheAlgorithms/C-Sharp","slug":"the-coin-cannot-be-lesser-or-equal-to-zero-nameof-coin","errorCode":null,"errorMessage":"The coin cannot be lesser or equal to zero {nameof(coin)}.","messagePattern":"The coin cannot be lesser or equal to zero (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Problems/DynamicProgramming/CoinChange/DynamicCoinChangeSolver.cs","lineNumber":134,"sourceCode":"\n        while (nextCoin != 0)\n        {\n            nextCoin = GetMinimalNextCoin(currentCoin, changesTable);\n            var difference = currentCoin - nextCoin;\n            list.Add(difference);\n            currentCoin = nextCoin;\n        }\n\n        var result = list.ToArray();\n\n        return result;\n    }\n\n    private static void ValidateCoin(int coin)\n    {\n        if (coin <= 0)\n        {\n            throw new InvalidOperationException($\"The coin cannot be lesser or equal to zero {nameof(coin)}.\");\n        }\n    }\n\n    private static void ValidateCoinsArray(int[] coinsArray)\n    {\n        var coinsAsArray = coinsArray.ToArray();\n\n        if (coinsAsArray.Length == 0)\n        {\n            throw new InvalidOperationException($\"Coins array cannot be empty {nameof(coinsAsArray)}.\");\n        }\n\n        var coinsContainOne = coinsAsArray.Any(x => x == 1);\n\n        if (!coinsContainOne)\n        {\n            throw new InvalidOperationException($\"Coins array must contain coin 1 {nameof(coinsAsArray)}.\");\n        }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Problems/DynamicProgramming/CoinChange/DynamicCoinChangeSolver.cs#L116-L152","documentation":"ValidateCoin is a private validation helper (a generic guard) used by GenerateSingleCoinChanges; it throws InvalidOperationException when a coin value is zero or negative, since change-making is undefined for non-positive denominations. The faulting input is the coin value.","triggerScenarios":"Thrown at Algorithms/Problems/DynamicProgramming/CoinChange/DynamicCoinChangeSolver.cs:134 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Filter the coin denominations before solving so only positive values (>= 1) are passed in; note the solver also requires a coin of value 1.","Fix the caller that computes or reads the coin value so it cannot yield 0 or negatives (e.g. from a bad parse or empty difference step).","Replace the InvalidOperationException-based helper with argument validation up front so invalid coins are rejected before table generation starts."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}