Fixed null reference and include stack trace when exception is thrown.