Maybe these resources come in handy:
https://docs.mendix.com/refguide/log-message/ → you can include a stack trace in the message
If you would like log messages in the Mendix database instead of just in a log file, you could decide to use a marketplace component like this one: https://marketplace.mendix.com/link/component/159 but be careful: they are community supported.
I hope this helps.
If you want the error to show up at the screen, you need to use “Show message” with a parameter of the “$LatestError” variable.