namespace Agent.Core.Ollama;public record CatchLog(string Sender, string Message, Logger Logger);public static class TryCatchExtensions{ public static void TryCatchCustomMessage(CatchLog log, Action action) { try { action(); } catch { log.Logger.WriteLine(log.Sender, log.Message, LogColors.Red); } } public static void TryCatch(Action action, Action onCatch) { try { action(); } catch { onCatch(); } } public static bool ReturnTrueTryCatch(Action action, CatchLog log) { try { action(); return true; } catch { log.Logger.WriteLine(log.Sender, log.Message, LogColors.Red); return false; } } public static async Task<bool> ReturnTrueTryCatchAsync(Func<Task> action, CatchLog log) { try { await action(); return true; } catch { log.Logger.WriteLine(log.Sender, log.Message, LogColors.Red); return false; } }}
Documentation
TryCatchExtensions
Safe wrappers for fire-and-forget async work.
TryCatchExtensions.cs
TryCatchextensions that log failures without crashing the host process.