Pretty backtrace?

I know I can print my own backtrace for an exception with
exception.backtrace.join("\n")

But when an uncaught exception goes all the way up to Rails handler,
Rails prints out a nice prettified stacktrace that’s a bit better than
this. It is shortened and abbreviated.

Is there any way I can call a method somewhere to use Rails’s same logic
to shorten and prettify my own stacktrace in the same way before I print
it out myself?