Recent empirical work on financial crises documents that crises tend to occur when macroeconomic fundamentals are weak; but even after conditioning on an exhaustive list of fundamentals, a sizable random component to crises and associated capital flows remains. We develop a model of herd behavior consistent with these observations. Informational frictions together with standard debt default problems lead to volatile capital flows resembling hot money and financial crises. We show that repaying debt during difficult times identifies a government as financially resilient, enhances its reputation, and stabilizes capital flows. Bailing out governments deprives resilient countries of the opportunity to differentiate themselves from the nonresilient.