Getting the timing right can mean the difference between a successful bankruptcy and one that leaves debts behind.