Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!ucsd!ucbvax!cam-orl.UUCP!grw From: grw@cam-orl.UUCP (Geoff Wiginton) Newsgroups: comp.windows.x Subject: Re: Design problem with XSetIOErrorHandler Message-ID: <3230.9101241014@quince.cam-orl.co.uk> Date: 24 Jan 91 10:14:28 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 84 I have encountered the same problem when connecting to several displays. The solution I adopted was a bit of a hack, but does allow you to return from the IOErrorHandler. This involves the use of setjmp and longjmp and means you have to know where the problem is likely to occur within your code. The best explanation is an example....... #include #include static Display *display; static int IO_error_type; static jmp_buf Popup_error_env; static jmp_buf Destroy_error_env, Popdown_error_env; int NewIOErrorHandler(); main() { ......... XSetIOErrorHandler( NewIOErrorHandler ); ......... } ProcedureA(........) { IO_error_type = EXIT; if ( setjmp( ProcA_error_env ) == 0) { .......... Code using X display that may not exist anymore. ......... } else { ........... This code will be executed if the attempt to use the display fails. ........... } } int NewIOErrorHandler( display ) Display *display; { switch (IO_error_type) { case EXIT: { longjmp( ProcA_error_env, 1); break; } case POPUP: { longjmp( Popup_error_env, 1); break; } case POPDOWN: { longjmp( Popdown_error_env, 1); break; } default: { printf("Fatal X IO error. Sorry.\n"); Die(0,0,NULL,NULL); } } } Essentially, longjmp returns to the setjmp that set up the environment (in this case ProcA_error_env) with a non-zero value. All other times the setjmp will return a 0 value. This allows you to check if an error has occurred in a part of the code and to handle it accordingly. The crucial part is that the error handler is never returned from and so the application does not exit. Fcc: Default Subject: ------------------------------------------------------------------------------- Geoff Wiginton, Olivetti Research Lab grw@uk.co.cam-orl Old Adennbrookes Site, Cambridge (0223) 343398