error_handler(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’– 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:

  1. first it attempts to autoload Module. πŸ”„
  2. if that's not possible, an undef exception is raised. πŸ’€
  3. if it is possible to load Module and function Function/N is exported, it is called. βœ…
  4. otherwise, if function '$handle_undefined_function'/2 is exported, it is called as '$handle_undefined_function'(Function, Args). πŸ‘€
  5. otherwise an undef exception is raised. 😭
WARNING: defining '$handle_undefined_function'/2 in 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'/2 and 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 Module is interpreted, the interpreter is invoked and the return value of the interpreted Fun(Arg1,.., ArgN) call is returned. 🎬
  • otherwise, it returns, if possible, the value of apply(Fun, Args) after an attempt is made to autoload Module. if this is not possible, the call fails with exit reason undef. ⭐

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