{"record":{"id":"9d6d0443816d75b5","repo":"Cysharp/UniTask","slug":"exception","errorCode":null,"errorMessage":"exception","messagePattern":"exception","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenEach.cs","lineNumber":41,"sourceCode":"    {\n        public T Result { get; }\n        public Exception Exception { get; }\n\n        //[MemberNotNullWhen(false, nameof(Exception))]\n        public bool IsCompletedSuccessfully => Exception == null;\n\n        //[MemberNotNullWhen(true, nameof(Exception))]\n        public bool IsFaulted => Exception != null;\n\n        public WhenEachResult(T result)\n        {\n            this.Result = result;\n            this.Exception = null;\n        }\n\n        public WhenEachResult(Exception exception)\n        {\n            if (exception == null) throw new ArgumentNullException(nameof(exception));\n            this.Result = default;\n            this.Exception = exception;\n        }\n\n        public void TryThrow()\n        {\n            if (IsFaulted)\n            {\n                ExceptionDispatchInfo.Capture(Exception).Throw();\n            }\n        }\n\n        public T GetResult()\n        {\n            if (IsFaulted)\n            {\n                ExceptionDispatchInfo.Capture(Exception).Throw();\n            }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Cysharp/UniTask/blob/ceac8d6946b1125fe782cd171fbcb245b567dbf9/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WhenEach.cs#L23-L59","documentation":"Thrown by WhenEachResult<T>(Exception) constructor when the exception argument is null. A WhenEachResult is either a success (with a result value) or a failure (with an exception); constructing a failure result with a null exception is logically contradictory. The guard enforces that a faulted result always carries a real exception.","triggerScenarios":"Calling new WhenEachResult<T>((Exception)null) or new WhenEachResult<T>(someNullableException) where the nullable value is null. This typically happens inside WhenEach's internal completion handling rather than in user code directly.","commonSituations":"WhenEach enumerating tasks where a task faults with a null exception (unusual but possible via custom task sources). User code constructing WhenEachResult manually with an unchecked null exception variable.","solutions":["Null-check the exception before constructing a faulted WhenEachResult","If the exception could be null, provide a fallback exception (e.g., new InvalidOperationException(\"Unknown error\"))","Ensure task sources that fault always provide a non-null exception"],"exampleFix":"// before\nvar result = new WhenEachResult<T>(nullableException); // throws if null\n\n// after\nvar result = new WhenEachResult<T>(\n    nullableException ?? new InvalidOperationException(\"Task faulted with null exception\"));","handlingStrategy":"validation","validationCode":"if (exception == null)\n{\n    exception = new InvalidOperationException(\"Task faulted with null exception\");\n}\nvar result = new WhenEachResult<T>(exception);","typeGuard":"static Exception EnsureNonNull(Exception ex) =>\n    ex ?? new InvalidOperationException(\"Unknown error\");","tryCatchPattern":null,"preventionTips":["Null-check exceptions before constructing WhenEachResult","Ensure custom task sources always provide non-null exceptions on fault","Use a fallback exception for null cases"],"tags":["unitask","wheneach","null-argument","unity","csharp"],"backgroundTag":null,"analyzedSha":"ceac8d6946b1125fe782cd171fbcb245b567dbf9","analyzedAt":"2026-08-13T19:16:39.025Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}