Index: cheese-window.c
===================================================================
--- cheese-window.c	(revision 752)
+++ cheese-window.c	(working copy)
@@ -1325,14 +1325,14 @@
   menu = gtk_menu_new();
   menuitem = gtk_menu_item_new_with_label(_("Quit"));
   g_signal_connect_swapped(menuitem,"activate",
-			   GTK_SIGNAL_FUNC(cheese_window_cmd_close),
-			   NULL);
+               GTK_SIGNAL_FUNC(cheese_window_cmd_close),
+               NULL);
   gtk_menu_append(menu, menuitem);
   
   menuitem = gtk_menu_item_new_with_label(_("About"));
   g_signal_connect_swapped(menuitem,"activate",
-			   GTK_SIGNAL_FUNC(cheese_window_cmd_about), 
-			   cheese_window->window);
+               GTK_SIGNAL_FUNC(cheese_window_cmd_about), 
+               cheese_window->window);
   gtk_menu_append(menu, menuitem);
   
   hildon_window_set_menu (HILDON_WINDOW(cheese_window->window),GTK_MENU(menu));
@@ -1374,6 +1374,8 @@
   int x_resolution;
   int y_resolution;
   GtkWidget *message_area;
+
+  GError *error;
   
   g_object_get (cheese_window->gconf, "gconf_prop_x_resolution", &x_resolution,
                 "gconf_prop_y_resolution", &y_resolution, NULL);
@@ -1386,8 +1388,33 @@
 
   g_free (webcam_device);
 
-  cheese_webcam_setup (cheese_window->webcam);
+  error = NULL;
+  cheese_webcam_setup (cheese_window->webcam, &error);
 
+  if (error != NULL)
+  {
+    GtkDialog *dialog;
+
+    gdk_threads_enter ();
+
+    dialog = gtk_message_dialog_new (NULL,
+                                     0,
+                                     GTK_MESSAGE_ERROR, 
+                                     GTK_BUTTONS_OK, 
+                                     error->message);
+
+    g_error_free(error);
+
+    g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL);
+    gtk_window_set_title(GTK_WINDOW (dialog), "Critical Error");
+    gtk_dialog_run (dialog);
+
+    // Clean up and exit
+    cheese_window_cmd_close(NULL, cheese_window);
+
+    gdk_threads_leave ();
+  }
+
   g_signal_connect (cheese_window->webcam, "photo-saved",
                     G_CALLBACK (cheese_window_photo_saved_cb), cheese_window);
   g_signal_connect (cheese_window->webcam, "video-saved",
Index: cheese-webcam.c
===================================================================
--- cheese-webcam.c	(revision 752)
+++ cheese-webcam.c	(working copy)
@@ -40,6 +40,14 @@
 
 #define CHEESE_WEBCAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_WEBCAM, CheeseWebcamPrivate))
 
+#define CHEESE_WEBCAM_ERROR cheese_webcam_error_quark ()
+
+enum CheeseWebcamError
+{
+  CHEESE_WEBCAM_ERROR_UNKNOWN,
+  CHEESE_WEBCAM_ERROR_NOELT
+};
+
 typedef struct
 {
   char *video_device; 
@@ -141,8 +149,12 @@
 
 static const int NUM_EFFECTS = G_N_ELEMENTS (EFFECT_TO_PIPELINE_DESC);
 
+GQuark
+cheese_webcam_error_quark (void)
+{
+  return g_quark_from_static_string ("cheese-webcam-error-quark");
+}
 
-
 static void
 cheese_webcam_set_x_overlay (CheeseWebcam *webcam)
 {
@@ -245,7 +257,7 @@
 
 
   dbus_error_init (&error);
-  hal_ctx = libhal_ctx_new ();	
+  hal_ctx = libhal_ctx_new ();  
   if (hal_ctx == NULL) 
   {
     g_error ("error: libhal_ctx_new");
@@ -646,7 +658,7 @@
     format = NULL;
     for (i = 1; i < priv->num_webcam_devices ; i++)
     {
-	    if (g_strcmp0 (priv->webcam_devices[i].video_device, priv->device_name) == 0)
+        if (g_strcmp0 (priv->webcam_devices[i].video_device, priv->device_name) == 0)
           priv->selected_device = i;
     }
     CheeseWebcamDevice *selected_webcam = &(priv->webcam_devices[priv->selected_device]);
@@ -727,8 +739,14 @@
   return TRUE;
 }
 
+static void 
+cheese_element_create_failed (const char *factoryname, GError **error)
+{
+  g_set_error (error, CHEESE_WEBCAM_ERROR, CHEESE_WEBCAM_ERROR_NOELT, "The element '%s' could not be found.", factoryname);
+}
+
 static gboolean
-cheese_webcam_create_video_display_bin (CheeseWebcam *webcam)
+cheese_webcam_create_video_display_bin (CheeseWebcam *webcam, GError **error)
 {
   CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
   GstElement *tee, *video_display_queue, *video_scale, *video_sink, *save_queue;
@@ -740,20 +758,49 @@
 
   cheese_webcam_create_webcam_source_bin (webcam);
 
-  priv->effect_filter = gst_element_factory_make ("identity", "effect");
-  priv->csp_post_effect = gst_element_factory_make ("ffmpegcolorspace", "csp_post_effect");
+  if ((priv->effect_filter = gst_element_factory_make ("identity", "effect")) == NULL)
+  {
+    cheese_element_create_failed("identity", error);
+    return FALSE;
+  }
+  if ((priv->csp_post_effect = gst_element_factory_make ("ffmpegcolorspace", "csp_post_effect")) == NULL)
+  {
+    cheese_element_create_failed("ffmpegcolorspace", error);
+    return FALSE;
+  }
 
-  tee = gst_element_factory_make ("tee", "tee");
+  if ((tee = gst_element_factory_make ("tee", "tee")) == NULL)
+  {
+    cheese_element_create_failed("tee", error);
+    return FALSE;
+  }
   
-  save_queue = gst_element_factory_make ("queue", "save_queue");
+  if ((save_queue = gst_element_factory_make ("queue", "save_queue")) == NULL)
+  {
+    cheese_element_create_failed("queue", error);
+    return FALSE;
+  }
 
-  video_display_queue = gst_element_factory_make ("queue", "video_display_queue");
+  if ((video_display_queue = gst_element_factory_make ("queue", "video_display_queue")) == NULL)
+  {
+    cheese_element_create_failed("queue", error);
+    return FALSE;
+  }
 
-  video_scale = gst_element_factory_make ("videoscale", "video_scale");
+  if ((video_scale = gst_element_factory_make ("videoscale", "video_scale")) == NULL)
+  {
+    cheese_element_create_failed("videoscale", error);
+    return FALSE;
+  }
+
   /* Use bilinear scaling */
   g_object_set (video_scale, "method", 1, NULL);
 
-  video_sink = gst_element_factory_make ("gconfvideosink", "video_sink");
+  if ((video_sink = gst_element_factory_make ("gconfvideosink", "video_sink")) == NULL)
+  {
+    cheese_element_create_failed("gconfvideosink", error);
+    return FALSE;
+  }
 
 
   gst_bin_add_many (GST_BIN (priv->video_display_bin), priv->webcam_source_bin, 
@@ -779,7 +826,7 @@
 }
 
 static gboolean
-cheese_webcam_create_photo_save_bin (CheeseWebcam *webcam)
+cheese_webcam_create_photo_save_bin (CheeseWebcam *webcam, GError **error)
 {
   CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
   GstElement *csp_photo_save_bin;
@@ -790,8 +837,16 @@
 
   priv->photo_save_bin = gst_bin_new ("photo_save_bin");
 
-  csp_photo_save_bin = gst_element_factory_make ("ffmpegcolorspace", "csp_photo_save_bin");
-  priv->photo_sink = gst_element_factory_make ("fakesink", "photo_sink");
+  if ((csp_photo_save_bin = gst_element_factory_make ("ffmpegcolorspace", "csp_photo_save_bin")) == NULL)
+  {
+    cheese_element_create_failed("ffmpegcolorspace", error);
+    return FALSE;
+  }
+  if ((priv->photo_sink = gst_element_factory_make ("fakesink", "photo_sink")) == NULL)
+  {
+    cheese_element_create_failed("fakesink", error);
+    return FALSE;
+  }
 
   gst_bin_add_many (GST_BIN (priv->photo_save_bin), csp_photo_save_bin,
                     priv->photo_sink, NULL);
@@ -802,9 +857,9 @@
   gst_object_unref (GST_OBJECT (pad));
 
   caps = gst_caps_new_simple ("video/x-raw-rgb",
-      			      "bpp", G_TYPE_INT, 24,
-      			      "depth", G_TYPE_INT, 24,
-			      NULL);
+                      "bpp", G_TYPE_INT, 24,
+                      "depth", G_TYPE_INT, 24,
+                  NULL);
   ok = gst_element_link_filtered (csp_photo_save_bin, priv->photo_sink, caps);
   gst_caps_unref (caps);
 
@@ -817,7 +872,7 @@
 }
 
 static gboolean 
-cheese_webcam_create_video_save_bin (CheeseWebcam *webcam)
+cheese_webcam_create_video_save_bin (CheeseWebcam *webcam, GError **error)
 {
   CheeseWebcamPrivate *priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
 
@@ -829,20 +884,56 @@
 
   priv->video_save_bin = gst_bin_new ("video_save_bin");
 
-  priv->audio_source = gst_element_factory_make ("gconfaudiosrc", "audio_source");
-  audio_queue = gst_element_factory_make ("queue", "audio_queue");
-  audio_convert = gst_element_factory_make ("audioconvert", "audio_convert");
-  audio_enc = gst_element_factory_make ("vorbisenc", "audio_enc");
+  if ((priv->audio_source = gst_element_factory_make ("gconfaudiosrc", "audio_source")) == NULL)
+  {
+    cheese_element_create_failed("gconfaudiosrc", error);
+    return FALSE;
+  }
+  if ((audio_queue = gst_element_factory_make ("queue", "audio_queue")) == NULL)
+  {
+    cheese_element_create_failed("queue", error);
+    return FALSE;
+  }
+  if ((audio_convert = gst_element_factory_make ("audioconvert", "audio_convert")) == NULL)
+  {
+    cheese_element_create_failed("audioconvert", error);
+    return FALSE;
+  }
+  if ((audio_enc = gst_element_factory_make ("vorbisenc", "audio_enc")) == NULL)
+  {
+    cheese_element_create_failed("vorbisenc", error); 
+    return FALSE;
+  }
 
-  video_save_csp = gst_element_factory_make ("ffmpegcolorspace", "video_save_csp");
-  video_enc = gst_element_factory_make ("theoraenc", "video_enc");
+  if ((video_save_csp = gst_element_factory_make ("ffmpegcolorspace", "video_save_csp")) == NULL)
+  {
+    cheese_element_create_failed("ffmpegcolorspace", error);
+    return FALSE;
+  }
+  if ((video_enc = gst_element_factory_make ("theoraenc", "video_enc")) == NULL)
+  {
+    cheese_element_create_failed("theoraenc", error);
+    return FALSE;
+  }
   g_object_set (video_enc, "keyframe-force", 1, NULL);
-  video_save_scale = gst_element_factory_make ("videoscale", "video_save_scale");
+  if ((video_save_scale = gst_element_factory_make ("videoscale", "video_save_scale")) == NULL)
+  {
+    cheese_element_create_failed("videoscale", error);
+    return FALSE;
+  }
   /* Use bilinear scaling */
   g_object_set (video_save_scale, "method", 1, NULL);
 
-  mux = gst_element_factory_make ("oggmux", "mux");
-  priv->video_file_sink = gst_element_factory_make ("filesink", "video_file_sink");
+  if ((mux = gst_element_factory_make ("oggmux", "mux")) == NULL)
+  {
+    cheese_element_create_failed("oggmux", error);
+    return FALSE;
+  }
+  if ((priv->video_file_sink = gst_element_factory_make ("filesink", "video_file_sink")) == NULL)
+  {
+    cheese_element_create_failed("filesink", error);
+    return FALSE;
+  }
 
   gst_bin_add_many (GST_BIN (priv->video_save_bin), priv->audio_source, audio_queue,
                     audio_convert, audio_enc, video_save_csp, video_save_scale, video_enc, 
@@ -1129,7 +1220,7 @@
                                    g_param_spec_string ("device-name",
                                                          NULL,
                                                          NULL,
-							 "",
+                             "",
                                                          G_PARAM_READWRITE));
     
    g_object_class_install_property (object_class, PROP_X_RESOLUTION,
@@ -1193,21 +1284,39 @@
                            "x-resolution", x_resolution, 
                            "y-resolution", y_resolution, NULL);
   }
-	
+    
   return webcam;
 }
 
 void
-cheese_webcam_setup (CheeseWebcam *webcam)
+cheese_webcam_setup (CheeseWebcam *webcam, GError **error)
 {
   CheeseWebcamPrivate* priv = CHEESE_WEBCAM_GET_PRIVATE (webcam);
   gboolean ok = TRUE;
+  GError *tmp_error = NULL;
 
   cheese_webcam_detect_webcam_devices (webcam);
-  cheese_webcam_create_video_display_bin (webcam);
-  cheese_webcam_create_photo_save_bin (webcam);
-  cheese_webcam_create_video_save_bin (webcam);
+  cheese_webcam_create_video_display_bin (webcam, &tmp_error);
+  if (tmp_error != NULL)
+  {
+    g_propagate_error (error, tmp_error);
+    return;
+  }
 
+  cheese_webcam_create_photo_save_bin (webcam, &tmp_error);
+  if (tmp_error != NULL)
+  {
+    g_propagate_error (error, tmp_error);
+    return;
+  }
+
+  cheese_webcam_create_video_save_bin (webcam, &tmp_error);
+  if (tmp_error != NULL)
+  {
+    g_propagate_error (error, tmp_error);
+    return;
+  }
+
   priv->pipeline = gst_pipeline_new ("pipeline");
 
   gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_display_bin, 
Index: cheese-webcam.h
===================================================================
--- cheese-webcam.h	(revision 752)
+++ cheese-webcam.h	(working copy)
@@ -85,7 +85,7 @@
                                        char *webcam_device_name, 
                                        int x_resolution,
                                        int y_resolution);
-void 		 cheese_webcam_setup 			(CheeseWebcam *webcam);
+void 		 cheese_webcam_setup 			(CheeseWebcam *webcam, GError **error);
 void 		 cheese_webcam_play 			(CheeseWebcam *webcam);
 void 		 cheese_webcam_stop 			(CheeseWebcam *webcam);
 void 		 cheese_webcam_set_effect 		(CheeseWebcam *webcam, CheeseWebcamEffect effect);
