Catch exceptions in test functions.

Also, refactor the code quite a lot.
Replace foldl by foldr for string concatenation.
Merge pull request #4 from Sjlver/master

Catch exceptions in test functions.