{"record":{"id":"45a2fd10ae2cfc03","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-source-catch","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'source')","messagePattern":"Value cannot be null\\. \\(Parameter 'source'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs","lineNumber":19,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Collections.Generic;\nusing System.Reactive.Disposables;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    // TODO: Implement tail call behavior to flatten Catch chains.\n\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Catch<TSource, TException>(this IAsyncObservable<TSource> source, Func<TException, IAsyncObservable<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 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, TException>(this IAsyncObservable<TSource> source, Func<TException, ValueTask<IAsyncObservable<TSource>>> handler)\n            where TException : Exception","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Catch.cs#L1-L37","documentation":"The Catch operator subscribes to a source and, when it fails with TException, switches to the observable returned by handler; a null source fails the guard and throws ArgumentNullException. Validation happens when the operator is constructed, not at subscription time.","triggerScenarios":"Calling source.Catch<TException>(handler) where source is null, e.g. Catch(null, ex => fallback) via static syntax.","commonSituations":"Pipelines where a preceding operator or factory returned null; composing Catch over an optional stream that was not instantiated.","solutions":["Ensure the source IAsyncObservable<TSource> is non-null before calling Catch","Substitute AsyncObservable.Empty<TSource>(scheduler) for a legitimately absent source","Fix the upstream factory returning null"],"exampleFix":"// before\nvar result = AsyncObservable.Catch<int, TimeoutException>(null, ex => fallback);\n// after\nvar result = AsyncObservable.Catch<int, TimeoutException>(primary ?? AsyncObservable.Empty<int>(Scheduler.Default), ex => fallback);","handlingStrategy":"validation","validationCode":"if (source == null) throw new InvalidOperationException(\"Catch requires a non-null source observable\");","typeGuard":"bool IsObservable<T>(IAsyncObservable<T> s) => s is not null;","tryCatchPattern":"try { var result = source.Catch<TimeoutException>(handler); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"source\") { /* use fallback stream directly */ }","preventionTips":["Guard pipeline stages so null never propagates between operators","Return Empty(scheduler) for absent streams","Validate the upstream producer's contract"],"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"}