c++ - System exception handling on different platforms -


basically, how catch exceptions on mac/linux? is, exceptions, not intrinsic language, segfaults & integer division. compiling on msvc, __try __except perfect because stack handling allows catch exceptions , continue execution lower down stack.

now, extend program other platforms (mainly ones mentioned), have no idea how exception handling works on these platforms work. far understand, it's handled through posix signals? , of such, wont allow handle exception , continue lower down stack?

edit: valid (pseudo code)? see it, leave c++ blocks correctly , dont indulge myself in ub.

jmp_buf buffer;  template< typename func >     protected_code(func f) {         if(!setjmp(buffer) {             f();                 }          else         {             throw std::exception("exception happened in f()"):         }     }   void sig_handler()  {     longjmp(buffer); }  int main() {     sigaction(sig_handler);      try {          protected_code( [&]              {                 1/0;             }         );     }     catch(const std::exception & e) {         ...     } } 

edit 2: wow reason never thought of throwing c++ exception signal handler, no need use longjmp/setjmp then. of course relies on fact thread calling signal handler same stack , thread faulted. defined/guaranteed somewhere? code example:

void sig_handler(int arg) {     throw 4; }  int main() {      signal(sigfpe, sig_handler);      try {         int 0 = 1;         zero--;         int ret = 1/zero;     } catch(int x) {         printf("catched %d\n", x);     }     return 0; } 

in unix, you'd catch processor faults signal handlers, using sigaction function install suitable handler signal want handle.

(i think mean __try ... __except rather __try ... __catch.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -