error_handler(3)
π NAME π
error_handler β the default system error handler, bestie. it's the module that decides what goes down when certain kinds of errors pop off. π¨
πΈ DESCRIPTION πΈ
okay so this module literally defines what happens when certain types of errors occur. that's the whole job. that's the vibe. π
and the best part? you can swap out the error handler of a process whenever you want, by calling:
erlang:process_flag(error_handler, NewErrorHandler)
so yeah, you're not stuck with the default. main character energy fr fr. β¨
π Notes π
ok listen up because this part is serious. π
the code in error_handler is complex. do not change it unless you fully understand the interaction between the error handler, the init process of the code server, and the I/O mechanism of the code. like, fully fully. no vibes-based editing here, bestie. π
code changes that seem small can cause a deadlock, because unforeseen consequences can occur. π and the use of input is dangerous in this type of code. periodt.
β¨ FUNCTIONS β¨
π¦ raise_undef_exception(Module, Function, Args) -> no_return()
when
Module :: atom(),
Function :: atom(),
Args :: list().
raises an undef exception with a stacktrace, indicating that Module:Function/N is undefined. that's it, that's the whole thing, and it's iconic for it. π
π undefined_function(Module, Function, Args) -> any()
when
Module :: atom(),
Function :: atom(),
Args :: list().
so this one gets called by the runtime system if a call is made to Module:Function(Arg1,.., ArgN) and Module:Function/N is undefined. heads up though: this function is evaluated inside the process making the original call. π«Ά
here's the flow, step by step:
- first it attempts to autoload
Module. π - if that's not possible, an
undefexception is raised. π - if it is possible to load
Moduleand functionFunction/Nis exported, it is called. β - otherwise, if function
'$handle_undefined_function'/2is exported, it is called as'$handle_undefined_function'(Function, Args). π - otherwise an
undefexception is raised. π
WARNING: defining'$handle_undefined_function'/2in ordinary application code is highly discouraged. it is very easy to make subtle errors that can take a long time to debug. furthermore, none of the tools for static code analysis (such as Dialyzer and Xref) supports the use of'$handle_undefined_function'/2and no such support will be added. only use this function after having carefully considered other, less dangerous, solutions. one example of potential legitimate use is creating stubs for other sub-systems during testing and debugging. π§ͺπ§
like... the audacity of that function honestly. respect the warning bestie, it's there for a reason. π
π§ undefined_lambda(Module, Fun, Args) -> term()
when
Module :: atom(),
Fun :: fun(),
Args :: list().
this function is evaluated if a call is made to Fun(Arg1,.., ArgN) when the module defining the fun is not loaded. and same as before β the function is evaluated inside the process making the original call. π«§
here's how it goes:
- if
Moduleis interpreted, the interpreter is invoked and the return value of the interpretedFun(Arg1,.., ArgN)call is returned. π¬ - otherwise, it returns, if possible, the value of
apply(Fun, Args)after an attempt is made to autoloadModule. if this is not possible, the call fails with exit reasonundef. β
and that's the whole page, slay. π this little masterpiece came to you from Ericsson AB, living in kernel 11.0.3, and it's the error_handler(3) page β go forth and handle your errors responsibly, bestie. ππβ¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms