{"record":{"id":"9c27ca068dfba643","repo":"netchx/netch","slug":"unhandled-exception-e-message","errorCode":null,"errorMessage":"Unhandled Exception\n{e.Message}","messagePattern":"Unhandled Exception\n(.+?)","errorType":"exception","errorClass":"MessageException","httpStatus":null,"severity":"error","filePath":"Netch/Controllers/MainController.cs","lineNumber":90,"sourceCode":"\n            await ModeController.StartAsync(Socks5Server, mode);\n        }\n        catch (Exception e)\n        {\n            releaser.Dispose();\n            await StopAsync();\n\n            switch (e)\n            {\n                case DllNotFoundException:\n                case FileNotFoundException:\n                    throw new Exception(e.Message + \"\\n\\n\" + i18N.Translate(\"Missing File or runtime components\"));\n                case MessageException:\n                    throw;\n                default:\n                    Log.Error(e, \"Unhandled Exception When Start MainController\");\n                    Utils.Utils.Open(Constants.LogFile);\n                    throw new MessageException($\"{i18N.Translate(\"Unhandled Exception\")}\\n{e.Message}\");\n            }\n        }\n    }\n\n    public static async Task StopAsync()\n    {\n        if (Lock.CurrentCount == 0)\n        {\n            (await Lock.EnterAsync()).Dispose();\n            if (ServerController == null && ModeController == null)\n                // stopped\n                return;\n\n            // else begin stop\n        }\n\n        using var _ = await Lock.EnterAsync();\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/netchx/netch/blob/9d99eb1c5a2acbf2a34f2600f94242601019a300/Netch/Controllers/MainController.cs#L72-L108","documentation":"Catch-all in MainController.StartAsync for any exception during startup that is not MessageException, DllNotFoundException, or FileNotFoundException. It logs the full exception to Serilog, opens Constants.LogFile for the user, and rethrows a MessageException with a generic 'Unhandled Exception' wrapper plus the original message. The original stack trace is in the log, not in the surfaced message.","triggerScenarios":"NullReferenceException, InvalidOperationException, UnauthorizedAccessException (no admin), network/socket exceptions, or any bug inside a controller's StartAsync that wasn't already a MessageException.","commonSituations":"Netch not run as administrator when a controller needs elevation; a code regression throwing on a null server/mode field; firewall/rule APIs throwing Win32 errors; race between Start and Stop mutating controller fields.","solutions":["Open the log file that was just launched (Constants.LogFile) and read the full stack trace of the 'Unhandled Exception When Start MainController' entry.","If the cause is UnauthorizedAccess/Win32, relaunch Netch as administrator.","Address the specific inner exception type from the log.","If it looks like a bug, report it with the log attached."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await MainController.StartAsync(server, mode); }\ncatch (MessageException ex) when (ex.Message.StartsWith(\"Unhandled Exception\"))\n{\n    // The full stack trace was already written to Constants.LogFile and opened.\n    // Read the latest 'Unhandled Exception When Start MainController' entry for triage.\n    Log.Information(\"Surfaced unhandled start failure; see {LogFile}\", Constants.LogFile);\n}","preventionTips":["Run Netch as administrator so Win32/route/firewall APIs don't throw UnauthorizedAccess.","Always attach the log file (which the controller opens for you) when reporting.","Don't Start while a Stop is in flight — let the async lock settle.","Keep server/mode objects non-null and validated before Start."],"tags":["error-handling","startup","logging","catch-all"],"backgroundTag":null,"analyzedSha":"9d99eb1c5a2acbf2a34f2600f94242601019a300","analyzedAt":"2026-08-13T14:12:19.105Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}