While there were plenty of laughs from the audience, Mr Chalmers offered a stirring call to arms to the graduates not to let disappointments hinder them from achieving their goals.

He said: “I want to invite you to guard, protect and grow that optimism throughout your life.

“Many things will happen to you – things that may leave you at rock bottom with the stuffing hanging out of your hopes, but the very same things can be the making of your character and the most profound learning experiences of life.”

Speaking after the ceremony, Rev Chalmers admitted he was surprised to learn he was to receive the doctorate.

He said: “It feels extraordinary, I feel first of all that it shouldn’t be happening to me and that there are lots more people in the world that are perhaps more deserving than I am.

“But yet, here I am, and I am here because so many people in my family and among my friends have made it possible for me to do the things that I have done. ”

And Rev Chalmers said it was important to remember that religious faith still had a rightful place in academic life, despite an increasingly secular society,

He added: “I think there’s a false dichotomy that suggests that science and academic investigation that is so much a part of modern life has rendered God redundant and I just don’t believe that.

“I believe that what academia finds out, what science discovers, adds to the wonder of the universe and the need to explore what happened the moment before creation, anot just what happened after the Big Bang.”

Rev Chalmers was appointed as moderator in 2014, replacing Reverend Angus Morrison.

Prior to becoming a minister, he studied chemical engineering at the Strathclyde University, before transferring to Glasgow to study divinity.

He also serves as the honorary chaplain to the Queen, and is one of Her Majesty’s personal ministers.