System: Win XP SP2 (all updates), AMD X2 4800.
Compiler/IDE: Turbo Delphi.
Libraries/API: Standard SysUtils & Math.

-----

Basically what I'm doing is factorization. I figured that it would be a fun experiment in recursion and wouldn't take long, but boy I was wrong! Basically I have a dynamic array of words and a function that (can) recursively factor numbers. In fact, it'll factor 37,777 sum the factors and factor those without a hitch. But, try factoring 456 and I get a stack overflow!

How?

456 = 2 x 2 x 2 x 57;

That shouldn't be hard to test or factor, but I seem to have done something incorrectly here.

Edit: factorizing 456 by 57 works, but not the automatic way around.

Part of the trouble is in preventing factorable numbers being in the output when they aren't wanted. I have a way that you can call the same function looking for a specific factor, and if that factor is 0 it just does some standard factorization. Anything that isn't prime gets factorized, and so on recursively. At the end is a quick bubblesort to order things numerically.

How do I go about catching something like this in my code? I've never dealt with a stack overflow, honestly, so I have no clue how to do it. Should I go into a larger number for my iterator in factorization? I figured at 65k limit on factors was safe for the maximum factor of ~65k.

I'll give the code if it helps, but I want to learn to catch this guy without 100% specific pointers to an area of my code. Thank you in advance.