Index: trunk/ippScripts/scripts/stack_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/stack_skycell.pl	(revision 21371)
+++ trunk/ippScripts/scripts/stack_skycell.pl	(revision 22430)
@@ -29,4 +29,15 @@
 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
 use Pod::Usage qw( pod2usage );
+
+# Look for programs we need
+my $missing_tools;
+my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
+my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($stack_id, $dbname, $outroot, $debug, $run_state, $threads, $reduction, $verbose, $no_update, $no_op, $redirect, $save_temps);
@@ -55,7 +66,10 @@
     and defined $run_state;
 
+# Unhandled exceptions should be passed on to my_die so they get pushed into the database
+$SIG{__DIE__} = sub { die @_ if $^S;
+                      my_die( $_[0], $stack_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # XXX camera is not known here; cannot use filerules...
 # my $logDest = $ipprc->filename("LOG.EXP", $outroot);
-
 my $logDest = "$outroot.log";
 
@@ -72,15 +86,4 @@
 my $image_id = $stack_id;
 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_STACK);
-
-# Look for programs we need
-my $missing_tools;
-my $stacktool = can_run('stacktool') or (warn "Can't find stacktool" and $missing_tools = 1);
-my $ppStack = can_run('ppStack') or (warn "Can't find ppStack" and $missing_tools = 1);
-my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
-my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 # Get list of components for stacking
@@ -300,6 +303,6 @@
 
     unless ($my_die_called) {
-	$my_die_called = 1;
-	delete_temps() unless ($save_temps);
+        $my_die_called = 1;
+        delete_temps() unless ($save_temps);
     }
 
@@ -324,6 +327,6 @@
 {
     unless ($temp_images_exist) {
-	print "No temporary images yet generated\n";
-	return 1;
+        print "No temporary images yet generated\n";
+        return 1;
     }
 
@@ -334,8 +337,8 @@
     unless ($success) {
         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	&my_die("Unable to perform ppConfigDump: $error_code", $stack_id, $error_code);
+        &my_die("Unable to perform ppConfigDump: $error_code", $stack_id, $error_code);
     }
     my $md = $mdcParser->parse(join "", @$stdout_buf) or
-	&my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to parse metadata config doc", $stack_id, $PS_EXIT_PROG_ERROR);
 
     my $temp_delete = metadataLookupBool($md, 'TEMP.DELETE'); # Delete temporary files?
