What's happening here is that meck:new
spawns a new process (a gen_server
process using the meck_proc
callback module), and that process exits with the undefined_module
error. (You can get it not to do that by passing the non_strict
option to meck:new
.) This new process is linked to the calling process, which means that an exit signal will be sent to the calling process, and the calling process will exit as well, without being able to catch
the signal.
You can avoid that by making your calling process trap exits:
process_flag(trap_exit, true)
which will turn the exit signal into a message that you can receive
; see the manual for more details. However, as a general rule you should avoid trapping exits, as it makes error handling more complicated (as opposed to the default "crash, restart").