*** gtk.py.orig	Thu Jul 20 17:43:04 2000
--- gtk.py	Thu Jul 20 17:43:17 2000
***************
*** 2784,2786 ****
--- 2784,2790 ----
  	return _gtk.gdk_window_foreign_new(xid)
  def _root_window():
  	return _gtk.gdk_get_root_win()
+ 
+ def pygtk_set_exception_handler (handler):
+     return _gtk.pygtk_set_exception_handler (handler)
+ 
*** gtkmodule.c.orig	Thu Jul 20 16:39:27 2000
--- gtkmodule.c	Thu Jul 20 17:30:19 2000
***************
*** 3182,3187 ****
--- 3182,3233 ----
    return 0;
  }
  
+ 
+ static PyObject *exceptionHandler = NULL;
+ 
+ static void HandleException (void) {
+     if (exceptionHandler != Py_None) {
+ 	PyObject * args, * result;
+ 	int isTrue;
+ 
+ 	args = PyTuple_New(0);
+ 	if (!args)
+ 	    goto error;
+ 	result = PyEval_CallObject (exceptionHandler, args);
+ 	if (!result)
+ 	    goto error;
+ 	Py_DECREF(args);
+ 	isTrue = PyObject_IsTrue (result);
+ 	Py_DECREF(result);
+ 	if (!isTrue)
+ 	    goto error;
+     } else {
+ error:
+ 	PyErr_Print();
+ 	PyErr_Clear();
+ 
+ 	if (PyGtk_FatalExceptions)
+ 	    gtk_main_quit();
+     }
+ }
+ 
+ static PyObject * PyGtk_SetExceptionHandler (PyObject * self,
+ 	    PyObject * args)
+ {
+     PyObject * result = NULL, * temp;
+ 
+     if (PyArg_ParseTuple(args, "O:PyGtk_SetExceptionHandler", &temp)) {
+ 	if (temp != Py_None && !PyCallable_Check(temp)) {
+ 	    PyErr_SetString(PyExc_TypeError, "parameter must be callable or None");
+ 	    return NULL;
+ 	}
+ 	Py_XINCREF(temp);
+ 	result = exceptionHandler;
+ 	exceptionHandler = temp;
+     }
+     return result;
+ }
+ 
  /* generic callback marshal */
  static void PyGtk_CallbackMarshal(GtkObject *o, gpointer data, guint nargs,
  				  GtkArg *args) {
***************
*** 3224,3235 ****
      ret = PyObject_CallObject(func, params);
      Py_DECREF(params);
      if (ret == NULL) {
! 	if (PyGtk_FatalExceptions)
! 	    gtk_main_quit();
! 	else {
! 	    PyErr_Print();
! 	    PyErr_Clear();
! 	}
  	PyGTK_UNBLOCK_THREADS
  	return;
      }
--- 3270,3276 ----
      ret = PyObject_CallObject(func, params);
      Py_DECREF(params);
      if (ret == NULL) {
! 	HandleException();
  	PyGTK_UNBLOCK_THREADS
  	return;
      }
***************
*** 3266,3277 ****
      Py_DECREF(params);
  
      if (ret == NULL) {
!         if (PyGtk_FatalExceptions)
! 	    gtk_main_quit();
! 	else {
! 	    PyErr_Print();
! 	    PyErr_Clear();
! 	}
  	PyGTK_UNBLOCK_THREADS
  	return;
      }
--- 3307,3313 ----
      Py_DECREF(params);
  
      if (ret == NULL) {
! 	HandleException();
  	PyGTK_UNBLOCK_THREADS
  	return;
      }
***************
*** 3301,3312 ****
      else
  	ret = PyObject_CallObject(func, NULL);
      if (ret == NULL) {
! 	if (PyGtk_FatalExceptions)
! 	    gtk_main_quit();
! 	else {
! 	    PyErr_Print();
! 	    PyErr_Clear();
! 	}
  	*GTK_RETLOC_BOOL(args[0]) = FALSE;
  	PyGTK_UNBLOCK_THREADS
  	    return;
--- 3337,3343 ----
      else
  	ret = PyObject_CallObject(func, NULL);
      if (ret == NULL) {
! 	HandleException();
  	*GTK_RETLOC_BOOL(args[0]) = FALSE;
  	PyGTK_UNBLOCK_THREADS
  	    return;
***************
*** 3330,3341 ****
    ret = PyObject_CallObject(func, tuple);
    Py_DECREF(tuple);
    if (ret == NULL) {
!     if (PyGtk_FatalExceptions)
!       gtk_main_quit();
!     else {
!       PyErr_Print();
!       PyErr_Clear();
!     }
    } else
      Py_DECREF(ret);
    PyGTK_UNBLOCK_THREADS
--- 3361,3367 ----
    ret = PyObject_CallObject(func, tuple);
    Py_DECREF(tuple);
    if (ret == NULL) {
!     HandleException();
    } else
      Py_DECREF(ret);
    PyGTK_UNBLOCK_THREADS
***************
*** 4753,4764 ****
    ret = PyObject_CallFunction(callback, "iO", action,
  			      PyGtk_New((GtkObject *)widget));
    if (ret == NULL) {
!     if (PyGtk_FatalExceptions)
!       gtk_main_quit();
!     else {
!       PyErr_Print();
!       PyErr_Clear();
!     }
    } else
      Py_DECREF(ret);
    PyGTK_UNBLOCK_THREADS
--- 4779,4785 ----
    ret = PyObject_CallFunction(callback, "iO", action,
  			      PyGtk_New((GtkObject *)widget));
    if (ret == NULL) {
!     HandleException();
    } else
      Py_DECREF(ret);
    PyGTK_UNBLOCK_THREADS
***************
*** 4830,4841 ****
      ret = PyObject_CallFunction(func, "Oii", PyGtk_New(GTK_OBJECT(menu)),
  				*x, *y);
      if (ret == NULL || !PyArg_ParseTuple(ret, "ii", x, y)) {
!         if (PyGtk_FatalExceptions)
! 	    gtk_main_quit();
!         else {
! 	    PyErr_Print();
! 	    PyErr_Clear();
! 	}
          if (ret) {
  	  Py_DECREF(ret);
  	}
--- 4851,4857 ----
      ret = PyObject_CallFunction(func, "Oii", PyGtk_New(GTK_OBJECT(menu)),
  				*x, *y);
      if (ret == NULL || !PyArg_ParseTuple(ret, "ii", x, y)) {
! 	HandleException();
          if (ret) {
  	  Py_DECREF(ret);
  	}
***************
*** 6542,6547 ****
--- 6558,6564 ----
  #ifdef HAVE_NUMPY
      { "gdk_draw_array", _wrap_gdk_draw_array, 1 },
  #endif
+     { "pygtk_set_exception_handler", PyGtk_SetExceptionHandler, METH_VARARGS },
      { NULL, NULL }
  };
  
***************
*** 6590,6595 ****
--- 6607,6616 ----
  #ifdef HAVE_NUMPY
       import_array();
  #endif
+ 
+      /* Default exceptionHandler */
+      Py_XINCREF(Py_None);
+      exceptionHandler = Py_None;
  
       /* initialise the boxed_funcs hash_table */
       boxed_funcs = g_hash_table_new(g_direct_hash, g_direct_equal);
