{"record":{"id":"403a0029249843b0","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-first-catch","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'first')","messagePattern":"Value cannot be null\\. \\(Parameter 'first'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs","lineNumber":60,"sourceCode":"                throw new ArgumentNullException(nameof(handler));\n\n            return Create(\n                source,\n                handler,\n                static async (source, handler, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Catch(observer, handler);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Catch<TSource>(this IAsyncObservable<TSource> first, IAsyncObservable<TSource> second)\n        {\n            if (first == null)\n                throw new ArgumentNullException(nameof(first));\n            if (second == null)\n                throw new ArgumentNullException(nameof(second));\n\n            return Create(\n                first,\n                second,\n                static async (first, second, observer) =>\n                {\n                    var (sink, inner) = AsyncObserver.Catch(observer, second);\n\n                    var subscription = await first.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, inner);\n                });\n        }\n\n        public static IAsyncObservable<TSource> Catch<TSource>(params IAsyncObservable<TSource>[] sources) => Catch((IEnumerable<IAsyncObservable<TSource>>)sources);\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs#L42-L78","documentation":"The two-sequence Catch(first, second) overload switches to second when first fails; a null first argument throws ArgumentNullException via the guard clause. Both operands are mandatory so the operator always has a stream to subscribe and a fallback.","triggerScenarios":"Calling Catch<TSource>(null, second) via static syntax, or chaining .Catch(second) on a null first observable.","commonSituations":"Primary stream from a connection/factory that returned null; merging Catch composition where an earlier variable was never assigned; optional primary sources treated as always-present.","solutions":["Ensure first is non-null; substitute AsyncObservable.Empty<TSource>(scheduler) when there is no primary","Reorder logic so second-only is expressed with second directly (or Empty as first) instead of null","Null-check the primary producer before composing Catch"],"exampleFix":"// before\nvar result = AsyncObservable.Catch<int>(primaryStream, backup); // primaryStream is null\n// after\nvar result = AsyncObservable.Catch<int>(primaryStream ?? AsyncObservable.Empty<int>(Scheduler.Default), backup);","handlingStrategy":"validation","validationCode":"if (first == null) throw new InvalidOperationException(\"Catch(first, second) requires a non-null first observable\");\nif (second == null) throw new InvalidOperationException(\"Catch(first, second) requires a non-null second observable\");","typeGuard":"bool IsObservable<T>(IAsyncObservable<T> s) => s is not null;","tryCatchPattern":"try { var result = first.Catch(second); }\ncatch (ArgumentNullException ex) when (ex.ParamName is \"first\" or \"second\") { /* substitute Empty for the null operand */ }","preventionTips":["Coalesce the primary stream with ?? Empty(scheduler) before Catch","Validate both sources when building resilient compositions","Keep primary streams from nullable producers explicitly defaulted"],"tags":["argument-null","reactive-extensions","error-handling"],"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"}