Count yourself lucky. Throwing a chain is no joke. The chain can whip and rip parts of your leg off and/or bind on the wheel hub, seize and down you go.
I had one go while canyon riding on my sportbike -- thankfully with no crash.
You know I was thinking I got pretty lucky after I saw what it did to the crank case. I had never heard of that happening before though so I wasn't too sure how common or how dangerous it was.
Sometimes it's not taking up excess slack in the chain; sometimes it's a worn, damaged or compromised chain; sometimes it's a worn out sprocket or one that breaks. On mine, the teeth of my rear sprocket broke under load (throttling out of a turn) and the chain was thrown off.
Cal's advice is good about replacing both sprockets and the chain once you sort out the case damage. You can run a search on the upper left as to case damage or repair. A good welder should be able to repair the damage. Unfortunately, you will be splitting the case to get there, so you will have an opportunity to inspect the lower end.