{"record":{"id":"0d19c50e7dbeb77e","repo":"TheAlgorithms/C-Sharp","slug":"nameof-maxstep-should-be-greater-than-zero","errorCode":null,"errorMessage":"{nameof(maxStep)} should be greater than zero","messagePattern":"(.+?) should be greater than zero","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Algorithms/Other/Mandelbrot.cs","lineNumber":68,"sourceCode":"        bool useDistanceColorCoding = true)\n    {\n        if (bitmapWidth <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapWidth),\n                $\"{nameof(bitmapWidth)} should be greater than zero\");\n        }\n\n        if (bitmapHeight <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(bitmapHeight),\n                $\"{nameof(bitmapHeight)} should be greater than zero\");\n        }\n\n        if (maxStep <= 0)\n        {\n            throw new ArgumentOutOfRangeException(\n                nameof(maxStep),\n                $\"{nameof(maxStep)} should be greater than zero\");\n        }\n\n        var bitmap = new SKBitmap(bitmapWidth, bitmapHeight);\n        var figureHeight = figureWidth / bitmapWidth * bitmapHeight;\n\n        // loop through the bitmap-coordinates\n        for (var bitmapX = 0; bitmapX < bitmapWidth; bitmapX++)\n        {\n            for (var bitmapY = 0; bitmapY < bitmapHeight; bitmapY++)\n            {\n                // determine the figure-coordinates based on the bitmap-coordinates\n                var figureX = figureCenterX + ((double)bitmapX / bitmapWidth - 0.5) * figureWidth;\n                var figureY = figureCenterY + ((double)bitmapY / bitmapHeight - 0.5) * figureHeight;\n\n                var distance = GetDistance(figureX, figureY, maxStep);\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Other/Mandelbrot.cs#L50-L86","documentation":"Mandelbrot.GetBitmap requires maxStep, the iteration cap controlling escape-time detail, to be strictly positive. After validating width and height it throws ArgumentOutOfRangeException when maxStep <= 0, since the per-pixel loop would otherwise never terminate meaningfully.","triggerScenarios":"Calling Algorithms.Other.Mandelbrot.GetBitmap with maxStep <= 0, e.g. GetBitmap(800, 600, 3.2, 0) or a negative step count passed from tuning code.","commonSituations":"Experimenting with iteration depth and passing 0; parsing a 'max iterations' config value where an empty field became 0; sign errors in generated parameters.","solutions":["Pass maxStep >= 1 (the default is 50)","Validate the iteration count before calling and clamp to at least 1","Fix the config/parse path that yielded 0 or a negative value"],"exampleFix":"// before\nvar bmp = Mandelbrot.GetBitmap(800, 600, 3.2, steps);\n// after\nvar bmp = Mandelbrot.GetBitmap(800, 600, 3.2, Math.Max(1, steps));","handlingStrategy":"validation","validationCode":"if (maxStep <= 0) throw new ArgumentException(\"maxStep must be positive\", nameof(maxStep));","typeGuard":"static bool IsValidIterationCount(int n) => n > 0;","tryCatchPattern":"try { var bmp = Mandelbrot.GetBitmap(w, h, figureWidth, steps); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"maxStep\")\n{\n    // retry with default maxStep = 50\n}","preventionTips":["Clamp iteration counts to at least 1","Guard parsed config integers against 0/negative defaults","Test tuning parameter boundaries (0, 1, large values)"],"tags":["argument-out-of-range","fractal","iteration","csharp"],"backgroundTag":"argument-out-of-range","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}