use try/catch instead of setjmp/longjmp also fix some c++ compile errors