Returning "magic numbers" to indicate failure is a debatable practice. Sun used -1 in many places, but not everywhere. Sometimes any integer would be a valid result, so a special integer for error cannot work and they throw an exception. You also get into the whole question of what's a failure and what's normal operation. Reading from a stream returns -1 at end because that's normal ... every stream eventually comes to an end. Reading from a stream that's not open gets an exception because that's a serious error.
In your example it might be appropriate (and much easier to read) to throw a variety of exceptions. See how this gets rid of a lot if if/else clauses:
This gets even cleaner if we throw the exceptions in called methods that do the details, like allocateMemory(). Then this code might look like:
Hope that made sense and gave you some ideas!
[ December 30, 2003: Message edited by: Stan James ]