{"record":{"id":"c89d99efdae2dbd8","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-handler-c89d99","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'handler')","messagePattern":"Value cannot be null\\. \\(Parameter 'handler'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs","lineNumber":26,"sourceCode":"{\n    public static partial class EnumerableEx\n    {\n        /// <summary>\n        /// Creates a sequence that corresponds to the source sequence, concatenating it with the sequence resulting from\n        /// calling an exception handler function in case of an error.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <typeparam name=\"TException\">Exception type to catch.</typeparam>\n        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"handler\">Handler to invoke when an exception of the specified type occurs.</param>\n        /// <returns>Source sequence, concatenated with an exception handler result sequence in case of an error.</returns>\n        public static IEnumerable<TSource> Catch<TSource, TException>(this IEnumerable<TSource> source, Func<TException, IEnumerable<TSource>> handler)\n            where TException : Exception\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (handler == null)\n                throw new ArgumentNullException(nameof(handler));\n\n            return CatchCore(source, handler);\n        }\n\n        /// <summary>\n        /// Creates a sequence by concatenating source sequences until a source sequence completes successfully.\n        /// </summary>\n        /// <typeparam name=\"TSource\">Source sequence element type.</typeparam>\n        /// <param name=\"sources\">Source sequences.</param>\n        /// <returns>Sequence that continues to concatenate source sequences while errors occur.</returns>\n        public static IEnumerable<TSource> Catch<TSource>(this IEnumerable<IEnumerable<TSource>> sources)\n        {\n            if (sources == null)\n                throw new ArgumentNullException(nameof(sources));\n\n            return CatchCore(sources);\n        }\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/System.Interactive/System/Linq/Operators/Catch.cs#L8-L44","documentation":"The Catch operator overload Catch<TSource,TException>(source, handler) throws ArgumentNullException with parameter name 'handler' when the exception-handler delegate is null. The delegate produces the replacement sequence when an exception of the specified type occurs, so the library rejects it eagerly at call time.","triggerScenarios":"Calling source.Catch(handler) where handler is a null Func<TException, IEnumerable<TSource>>, e.g. a conditional expression or method result that yielded null.","commonSituations":"A handler variable assigned from configuration or a registry that was not registered; refactoring removed the handler lambda; passing a null result from a factory method.","solutions":["Provide an actual handler lambda, e.g. ex => Enumerable.Empty<TSource>() or a recovery sequence.","Check why the handler expression evaluated to null (missing registration, failed lookup).","Coalesce: source.Catch(handler ?? (_ => Enumerable.Empty<T>())).","Use nullable-aware signatures with NRT enabled to catch it at compile time."],"exampleFix":"// before\nvar result = source.Catch<MyException>(null);\n// after\nvar result = source.Catch<MyException>(ex => Enumerable.Empty<int>());","handlingStrategy":"validation","validationCode":"if (handler is null)\n    throw new ArgumentNullException(nameof(handler));\n// or coalesce:\nhandler ??= ex => Enumerable.Empty<TSource>();","typeGuard":"static bool HasHandler<TSource, TException>(Func<TException, IEnumerable<TSource>> h) where TException : Exception => h != null;","tryCatchPattern":"try\n{\n    var result = source.Catch<MyException>(handler);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"handler\")\n{\n    var result = source.Catch<MyException>(_ => Enumerable.Empty<TSource>());\n}","preventionTips":["Always pass a concrete lambda; use ex => Enumerable.Empty<T>() for 'swallow and continue'.","Verify delegates resolved from registries/config are non-null before use.","Enable nullable reference types so null delegate arguments are flagged at compile time.","Coalesce nullable delegates with ??= at initialization."],"tags":["csharp","null-argument","linq","ix-net","argument-validation","delegate"],"backgroundTag":"null-argument","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}