Using "trace error" we see where the overflow actually happens:

Trapping the error using "on error" and returning the vital values just before the error would occur shows that it happens in the second loop of "i" and we also see that variables "a" and "c" are already very large and so the above calculation obviously exceeds the IEEE limit of approx. 10^307.

Looking at the last values of the vector Y which you create in the program shows that the values (first column is "a") increases very quickly after your limit of 315 is exceeded.
I don't know if "a" is supposed to grow that fast. At the end of the outer i-loop you have a break command if a exceeds 315 but obviously variable "a" is lower than 315 after the first loop (i=0) and 'explodes' within the inner j-loop when i=1.
Not sure what exactly you are trying to achieve. You may put the break command at the end of the inner loop, so this loop stops when a exceeds d/2, but the outer loop continues.
Or you may rather replace the "break" command by "return Y" so the whole program is ended when a exceeds d/2 in the inner loop.
Find both "fixes" in the attached file. I guess the second may be what you are looking for.