Error handling at compiling

now working, not really clean. Also read comments with commit
d5c190764e0d570cb314bfd6ecc28de56a898a25