Implement and use Error.stackTraceLimit and Error.prepareStackTrace.