Index: trunk/ippScripts/scripts/detrend_process_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 19942)
+++ trunk/ippScripts/scripts/detrend_process_imfile.pl	(revision 22430)
@@ -22,4 +22,14 @@
 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 $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
+my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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 ( $det_id, $exp_id, $class_id, $det_type, $exp_tag, $input_uri, $camera, $outroot, $dbname, $reduction,
@@ -55,4 +65,8 @@
     defined $outroot;
 
+# 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], $det_id, $exp_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # XXX this exits with status = 0 on failure
 $ipprc->define_camera($camera);
@@ -66,14 +80,4 @@
 my $ppimage_recipe = $ipprc->reduction($reduction, uc($det_type) . '_PROCESS'); # Recipe name for ppImage
 my $jpeg_recipe = $ipprc->reduction($reduction, uc($det_type) . '_JPEG_IMAGE'); # Recipe name for JPEG
-
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" 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_die("Couldn't find input file: $input_uri\n", $det_id, $exp_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
@@ -128,5 +132,5 @@
     }
     foreach my $line (@$stdout_buf) {
-	$cmdflags .= " $line";
+        $cmdflags .= " $line";
     }
     chomp $cmdflags;
