{"record":{"id":"5f001e4f122a11af","repo":"lucasg/Dependencies","slug":"unhandled-exception-occured-while-processing","errorCode":null,"errorMessage":"[!] Unhandled exception occured while processing \"{1:s}\"","messagePattern":"\\[!\\] Unhandled exception occured while processing \"(.+?)\"","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Dependencies/Program.cs","lineNumber":551,"sourceCode":"        private void SafeExecutor(Action action)\n        {\n            SafeExecutor(() => { action(); return 0; });\n        }\n\n        private T SafeExecutor<T>(Func<T> action)\n        {\n            try\n            {\n                return action();\n            }\n            catch (RethrownException rex)\n            {\n                Console.Error.WriteLine(\" - \\\"{0:s}\\\"\", Filepath);\n                throw rex;\n            }\n            catch (Exception ex)\n            {\n                Console.Error.WriteLine(\"[!] Unhandled exception occured while processing \\\"{1:s}\\\"\", RecursionLevel, Filepath);\n                Console.Error.WriteLine(\"Stacktrace:\\n{0:s}\\n\", ex.StackTrace);\n                Console.Error.WriteLine(\"Modules backtrace:\");\n                throw new RethrownException(ex);\n            }\n            finally\n            {\n                //\n                \n            }\n\n            // return default(T);\n        }\n\n        // Json exportable\n\t\tpublic string ModuleName;\n        public string Filepath;\n        public ModuleSearchStrategy SearchStrategy;\n        public List<PeDependencyItem> Dependencies","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/lucasg/Dependencies/blob/1997a40000b77bd3326cbc33672a7b9f78bb23f3/Dependencies/Program.cs#L533-L569","documentation":"Printed by SafeExecutor<T>'s generic catch(Exception ex) (Program.cs:551) when an UNRECOGNISED exception escapes the action lambda inside LoadPe()/ResolveDependencies(). Unlike the RethrownException branch, this is the first time the exception is seen, so it is wrapped in a new RethrownException (Program.cs:554) to start the module backtrace. NOTE: the format string uses {1:s} while passing (RecursionLevel, Filepath) as args, so Filepath is what is shown; RecursionLevel is passed but unused in this line.","triggerScenarios":"Any unhandled exception during PeDependencyItem.LoadPe() (BinaryCache.LoadPe / GetImports / Mono.Cecil ReadAssembly) or ResolveDependencies() (Root.ResolveModule / cache lookups) that is not itself a RethrownException.","commonSituations":"A PE import table references a module whose resolution throws an unexpected error; BinaryCache returns a PE in a bad state; a null ModuleFilepath is dereferenced; Mono.Cecil throws something other than the caught BadImageFormatException.","solutions":["Look at the Stacktrace line printed next (error 4) to find the throwing call site and method.","Reproduce with `-cache` off and a single target to reduce concurrency/noise, then fix the root cause at the identified call site.","If the cause is an unloadable transitive DLL, exclude it by lowering `-depth` or resolving the underlying file access problem."],"exampleFix":"// before (Program.cs:551) - RecursionLevel passed but unused, message is vague:\nConsole.Error.WriteLine(\"[!] Unhandled exception occured while processing \\\"{1:s}\\\"\", RecursionLevel, Filepath);\n// after - include depth and the exception message:\nConsole.Error.WriteLine(\"[!] Unhandled exception at depth {0} while processing \\\"{1:s}\\\" : {2}\", RecursionLevel, Filepath, ex.GetType().Name);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// SafeExecutor wraps any non-RethrownException into a RethrownException,\n// so callers only ever need to catch RethrownException at the boundary.\ntry\n{\n    Program.DumpDependencyChain(pe, Program.PrettyPrinter, depth);\n}\ncatch (RethrownException rex)\nwhen (rex.InnerException != null)\n{\n    // rex.InnerException is the original exception; its StackTrace was printed\n    // by SafeExecutor (errors 3-5) before wrapping.\n    Console.Error.WriteLine($\"Root cause: {rex.InnerException.GetType().Name}: {rex.InnerException.Message}\");\n}","preventionTips":["Pinpoint the failing call from the Stacktrace (error 4) before retrying - retrying unchanged just re-fails.","Run with a shallow `-depth 1` first to surface root-level failures before deep recursion."],"tags":["dependency-resolution","unhandled-exception","stderr","cli"],"backgroundTag":null,"analyzedSha":"1997a40000b77bd3326cbc33672a7b9f78bb23f3","analyzedAt":"2026-08-13T18:14:41.696Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}