This is an updated version of triangle including exception handling