I am just starting with Erlang, so there's nothing complex in my code yet. Often I do mistakes which lead to runtime errors.
The issue is I always see things like this:
{"init terminating in do_boot",{undef,[{'lexer_app.beam',start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
Crash dump is being written to: erl_crash.dump...done init terminating in do_boot ()
Which hardly gives me quick information on what went wrong.
Thus, I wonder, is the only way to debug the errors like this to look into erl_crash.dump, which is, frankly, looks like total abrakadabra and I need to somehow figure out even simple stupid errors by looking into it?
The main questions, is it possible to get more human-friendly errors, like "5:6 Person variable of type string is not assignable to type number"?
What's the usual workflow of debugging the app?
To handle a runtime error, the code can be placed within a try-catch block and the error can be caught inside the catch block.
stacktop([Top|_]) -> Top. ancestor(N) -> {_,Stacktrace}=erlang:process_info(self(),current_stacktrace), ancestor(N+1,Stacktrace). ancestor(1,S) -> format_stack_entry(stacktop(S)); ancestor(N,[_|T]) -> ancestor(N-1,T).
A runtime error in a program is an error that occurs while the program is running after being successfully compiled. Runtime errors are commonly called referred to as “bugs” and are often found during the debugging process before the software is released.
Error handling is not supported by C language. There are some other ways by which error handling can be done in C language. The header file “error. h” is used to print the errors using return statement function. It returns -1 or NULL in case of any error and errno variable is set with the error code.
You're not expected to be able to simply read the text of a crashdump file. Rather, you should be using the crashdump viewer, which is a graphical application that lets you view in a human-friendly manner all the information details a crashdump file contains.
If you just want to see pretty comnsole error message, you can do a little trick
7> {_type, {Reason, Stack}} = {"init terminating in do_boot",{undef,[{'lexer_app.beam',start,[],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}.
{"init terminating in do_boot",
{undef,[{'lexer_app.beam',start,[],[]},
{init,start_it,1,[]},
{init,start_em,1,[]}]}}
8> erlang:raise(exit, Reason, Stack).
** exception exit: undef
in function 'lexer_app.beam':start/0
called as 'lexer_app.beam':start()
in call from init:start_it/1
in call from init:start_em/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With