{"record":{"id":"18ecf7d9a1dde70e","repo":"dotnet/reactive","slug":"error","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Notification.cs","lineNumber":703,"sourceCode":"        /// <param name=\"value\">The value contained in the notification.</param>\n        /// <returns>The OnNext notification containing the value.</returns>\n        public static Notification<T> CreateOnNext<T>(T value)\n        {\n            return new Notification<T>.OnNextNotification(value);\n        }\n\n        /// <summary>\n        /// Creates an object that represents an OnError notification to an observer.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements received by the observer. Upon dematerialization of the notifications into an observable sequence, this type is used as the element type for the sequence.</typeparam>\n        /// <param name=\"error\">The exception contained in the notification.</param>\n        /// <returns>The OnError notification containing the exception.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"error\"/> is null.</exception>\n        public static Notification<T> CreateOnError<T>(Exception error)\n        {\n            if (error == null)\n            {\n                throw new ArgumentNullException(nameof(error));\n            }\n\n            return new Notification<T>.OnErrorNotification(error);\n        }\n\n        /// <summary>\n        /// Creates an object that represents an OnCompleted notification to an observer.\n        /// </summary>\n        /// <typeparam name=\"T\">The type of the elements received by the observer. Upon dematerialization of the notifications into an observable sequence, this type is used as the element type for the sequence.</typeparam>\n        /// <returns>The OnCompleted notification.</returns>\n        public static Notification<T> CreateOnCompleted<T>()\n        {\n            return Notification<T>.OnCompletedNotification.Instance;\n        }\n    }\n}\n\n#pragma warning restore CS0659","sourceCodeStart":685,"sourceCodeEnd":721,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Notification.cs#L685-L721","documentation":"Notification.CreateOnError<T>(Exception) throws ArgumentNullException when the error argument is null. An OnError notification must carry a non-null Exception, since observers receiving OnError expect a concrete exception instance. Thrown synchronously at factory time.","triggerScenarios":"Calling Notification.CreateOnError<T>(ex) where ex is null, e.g. from a catch that captured no exception or a null exception variable/property.","commonSituations":"Rethrow-style code paths where the exception object was never captured; APIs that return a null Exception on failure then feed it to CreateOnError.","solutions":["Pass an actual exception instance; create one if none exists, e.g. new Exception(\"unknown error\").","Skip creating the notification and use CreateOnCompleted<T>() if there is genuinely no error.","Null-check the exception before calling CreateOnError and fall back to a synthesized exception."],"exampleFix":"// before\nvar n = Notification.CreateOnError<int>(maybeEx); // maybeEx may be null\n// after\nvar n = Notification.CreateOnError<int>(maybeEx ?? new Exception(\"unknown error\"));","handlingStrategy":"validation","validationCode":"if (error == null) error = new Exception(\"unknown error\");\nvar n = Notification.CreateOnError<int>(error);","typeGuard":"bool HasError(Exception e) => e != null;","tryCatchPattern":"try { var n = Notification.CreateOnError<int>(error); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"error\") { var n = Notification.CreateOnError<int>(new Exception(\"unknown error\")); }","preventionTips":["Never store exceptions in nullable variables you later feed to CreateOnError.","Synthesize an exception (with context message) when the original is unavailable.","Prefer wrapping real caught exceptions rather than propagating null Exception values through your pipeline."],"tags":["argument-null","reactive-extensions","notification"],"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"}