diff --git a/Graphics/X11/Xlib/Color.hs b/Graphics/X11/Xlib/Color.hs
--- a/Graphics/X11/Xlib/Color.hs
+++ b/Graphics/X11/Xlib/Color.hs
@@ -58,6 +58,7 @@
         xLookupColor :: Display -> Colormap -> CString ->
                 Ptr Color -> Ptr Color -> IO Status
 
+-- TODO don't throw an exception.
 -- | interface to the X11 library function @XAllocNamedColor()@.
 allocNamedColor :: Display -> Colormap -> String -> IO (Color, Color)
 allocNamedColor display colormap color_name =
diff --git a/Graphics/X11/Xlib/Event.hsc b/Graphics/X11/Xlib/Event.hsc
--- a/Graphics/X11/Xlib/Event.hsc
+++ b/Graphics/X11/Xlib/Event.hsc
@@ -456,7 +456,7 @@
         flush        :: Display ->               IO ()
 
 -- | interface to the X11 library function @XSync()@.
-foreign import ccall unsafe "HsXlib.h XSync"
+foreign import ccall safe "HsXlib.h XSync"
         sync         :: Display -> Bool ->       IO ()
 
 -- | interface to the X11 library function @XPending()@.
diff --git a/Graphics/X11/Xlib/Extras.hsc b/Graphics/X11/Xlib/Extras.hsc
--- a/Graphics/X11/Xlib/Extras.hsc
+++ b/Graphics/X11/Xlib/Extras.hsc
@@ -1306,7 +1306,11 @@
     xGetWMHints :: Display -> Window -> IO (Ptr WMHints)
 
 getWMHints :: Display -> Window -> IO WMHints
-getWMHints dpy w = xGetWMHints dpy w >>= peek
+getWMHints dpy w = do
+    p <- xGetWMHints dpy w
+    if p == nullPtr
+        then return $ WMHints 0 False 0 0 0 0 0 0 0
+        else peek p
 
 foreign import ccall unsafe "XlibExtras.h XAllocWMHints"
     xAllocWMHints :: IO (Ptr WMHints)
@@ -1371,3 +1375,62 @@
 
 foreign import ccall unsafe "HsXlib.h XConvertSelection"
     xConvertSelection :: Display -> Atom -> Atom -> Atom -> Window -> Time -> IO ()
+
+-------------------------------------------------------------------------------
+-- Error handling
+--
+type XErrorEventPtr = Ptr ()
+type CXErrorHandler = Display -> XErrorEventPtr -> IO CInt
+type XErrorHandler = Display -> XErrorEventPtr -> IO ()
+
+data ErrorEvent = ErrorEvent {
+    ev_type :: !CInt,
+    ev_display :: Display,
+    ev_serialnum :: !CULong,
+    ev_error_code :: !CUChar,
+    ev_request_code :: !CUChar,
+    ev_minor_code :: !CUChar,
+    ev_resourceid :: !XID
+}
+
+foreign import ccall safe "wrapper"
+    mkXErrorHandler :: CXErrorHandler -> IO (FunPtr CXErrorHandler)
+foreign import ccall safe "dynamic"
+    getXErrorHandler :: FunPtr CXErrorHandler -> CXErrorHandler
+foreign import ccall safe "HsXlib.h XSetErrorHandler"
+    _xSetErrorHandler :: FunPtr CXErrorHandler -> IO (FunPtr CXErrorHandler)
+
+-- |A binding to XSetErrorHandler.
+--  NOTE:  This is pretty experimental because of safe vs. unsafe calls.  I
+--  changed sync to a safe call, but there *might* be other calls that cause a
+--  problem
+setErrorHandler :: XErrorHandler -> IO ()
+setErrorHandler new_handler = do
+    _handler <- mkXErrorHandler (\d -> \e -> new_handler d e >> return 0)
+    _xSetErrorHandler _handler
+    return ()
+
+-- |Retrieves error event data from a pointer to an XErrorEvent and
+--  puts it into an ErrorEvent.
+getErrorEvent :: XErrorEventPtr -> IO ErrorEvent
+getErrorEvent ev_ptr = do
+    _type <- #{peek XErrorEvent, type } ev_ptr
+    serial <- #{peek XErrorEvent, serial} ev_ptr
+    dsp <- fmap Display (#{peek XErrorEvent, display} ev_ptr)
+    error_code <- #{peek XErrorEvent, error_code} ev_ptr
+    request_code <- #{peek XErrorEvent, request_code} ev_ptr
+    minor_code <- #{peek XErrorEvent, minor_code} ev_ptr
+    resourceid <- #{peek XErrorEvent, resourceid} ev_ptr
+    return $ ErrorEvent {
+        ev_type = _type,
+        ev_display = dsp,
+        ev_serialnum = serial,
+        ev_error_code = error_code,
+        ev_request_code = request_code,
+        ev_minor_code = minor_code,
+        ev_resourceid = resourceid
+    }
+
+-- |A binding to XMapRaised.
+foreign import ccall unsafe "HsXlib.h XMapRaised"
+    mapRaised :: Display -> Window -> IO CInt
diff --git a/X11.cabal b/X11.cabal
--- a/X11.cabal
+++ b/X11.cabal
@@ -1,5 +1,5 @@
 name:		        X11
-version:	        1.4.1
+version:	        1.4.2
 license:	        BSD3
 license-file:	    LICENSE
 copyright:	        Alastair Reid, 1999-2003, libraries@haskell.org 2003-2007
@@ -49,4 +49,4 @@
 install-includes:   HsXlib.h, XlibExtras.h
 build-depends:	    base
 build-type:         Configure
-ghc-options:        -O2 -funbox-strict-fields -Wall -fno-warn-unused-binds
+ghc-options:        -funbox-strict-fields -Wall -fno-warn-unused-binds
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for Haskell X11 package 1.3.0.
+# Generated by GNU Autoconf 2.61 for Haskell X11 package 1.4.1.
 #
 # Report bugs to <dons@galois.com>.
 #
@@ -574,8 +574,8 @@
 # Identity of this package.
 PACKAGE_NAME='Haskell X11 package'
 PACKAGE_TARNAME='X11'
-PACKAGE_VERSION='1.3.0'
-PACKAGE_STRING='Haskell X11 package 1.3.0'
+PACKAGE_VERSION='1.4.1'
+PACKAGE_STRING='Haskell X11 package 1.4.1'
 PACKAGE_BUGREPORT='dons@galois.com'
 
 ac_unique_file="include/HsXlib.h"
@@ -1185,7 +1185,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures Haskell X11 package 1.3.0 to adapt to many kinds of systems.
+\`configure' configures Haskell X11 package 1.4.1 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1250,7 +1250,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of Haskell X11 package 1.3.0:";;
+     short | recursive ) echo "Configuration of Haskell X11 package 1.4.1:";;
    esac
   cat <<\_ACEOF
 
@@ -1341,7 +1341,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-Haskell X11 package configure 1.3.0
+Haskell X11 package configure 1.4.1
 generated by GNU Autoconf 2.61
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1355,7 +1355,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by Haskell X11 package $as_me 1.3.0, which was
+It was created by Haskell X11 package $as_me 1.4.1, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
@@ -5249,7 +5249,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by Haskell X11 package $as_me 1.3.0, which was
+This file was extended by Haskell X11 package $as_me 1.4.1, which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -5298,7 +5298,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-Haskell X11 package config.status 1.3.0
+Haskell X11 package config.status 1.4.1
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([Haskell X11 package], [1.3.0], [dons@galois.com], [X11])
+AC_INIT([Haskell X11 package], [1.4.1], [dons@galois.com], [X11])
 
 FP_ARG_X11
 
