Coerces an arbitrary thrown value into an Error instance.
Error
The caught value, which may or may not be an Error.
err unchanged if it is already an Error; otherwise a new Error whose message is String(err).
err
String(err)
try { risky()} catch (e) { const error = toError(e) // guaranteed Error logger.error(error.message)} Copy
try { risky()} catch (e) { const error = toError(e) // guaranteed Error logger.error(error.message)}
Coerces an arbitrary thrown value into an
Errorinstance.