{"record":{"id":"e3ac10f1779be4dc","repo":"louthy/language-ext","slug":"message","errorCode":null,"errorMessage":"message","messagePattern":"message","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Prelude/Prelude.cs","lineNumber":58,"sourceCode":"    [Pure]\n    public static Func<A, A> constantA<A>(A x) =>\n        _ => x;\n\n    /// <summary>\n    /// Constant function\n    /// Always returns the first argument\n    /// </summary>\n    [Pure]\n    public static A constantA<A>(A x, A _) =>\n        x;\n\n    /// <summary>\n    /// Raises a lazy Exception with the message provided\n    /// </summary>\n    /// <param name=\"message\">Exception message</param>\n    /// <returns>Action that when executed throws</returns>\n    public static Action failwith(string message) =>\n        () => throw new Exception(message);\n\n    /// <summary>\n    /// Raises an Exception with the message provided\n    /// </summary>\n    /// <typeparam name=\"R\">The return type of the expression this function is being used in.\n    /// This allows exceptions to be thrown in ternary operators, or LINQ expressions for\n    /// example</typeparam>\n    /// <param name=\"message\">Exception message</param>\n    /// <returns>Throws an exception</returns>\n    public static R failwith<R>(string message) =>\n        throw new Exception(message);\n\n    /// <summary>\n    /// Raises an ApplicationException with the message provided\n    /// </summary>\n    /// <typeparam name=\"R\">The return type of the expression this function is being used in.\n    /// This allows exceptions to be thrown in ternary operators, or LINQ expressions for\n    /// example</typeparam>","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Prelude/Prelude.cs#L40-L76","documentation":"Prelude.failwith(message) returns an Action that, when invoked, throws a plain System.Exception with the given message. The exception is lazy — it only fires when the returned delegate is executed. The message text is whatever the caller passed.","triggerScenarios":"Calling failwith(\"...\") to produce a throwing Action and then invoking that action (or passing it where an Action is executed, e.g. as a callback).","commonSituations":"Using failwith in exhaustive switch expressions or as placeholders for impossible branches; the exception surfaces at delegate-invocation time, often far from the failwith call site.","solutions":["Inspect the message string passed to failwith at the throw site and fix the impossible/unhandled branch it guards","Catch System.Exception around the delegate invocation if the failure is expected/recoverable","Prefer failwith<R> in expression positions or replace with proper Result/Option handling"],"exampleFix":"// before\nAction fail = failwith(\"unreachable branch\"); fail(); // throws Exception\n// after\nvar result = value switch { Some(var x) => x, _ => failwith<int>(\"unreachable branch\") }; // typed","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { failAction(); }\ncatch (Exception ex) { logger.LogWarning(\"failwith guard hit: {Msg}\", ex.Message); }\n// note: failwith returns a lazy Action; the throw happens at invocation","preventionTips":["Remember failwith() is lazy — the exception fires when the Action runs","Treat failwith sites as exhaustiveness assertions; keep them truly unreachable","Prefer Fin/Option error channels over exception-based flow"],"tags":["csharp","languageext","prelude"],"backgroundTag":"internal-invariant-violation","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}