Index: trunk/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 18562)
+++ trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 22430)
@@ -27,4 +27,12 @@
 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);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 my ($det_id, $iter, $det_type, $camera, $outroot, $filter, $dbname, $verbose, $no_update, $no_op, $redirect);
@@ -52,4 +60,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, $iter, $PS_EXIT_UNKNOWN_ERROR ); };
+
 # check for existing directory, generate if needed
 $ipprc->outroot_prepare($outroot);
@@ -89,12 +101,4 @@
 my $rejstats = PS::IPP::Metadata::Stats->new($REJSTATS); # Stats parser
 
-# Look for programs we need
-my $missing_tools;
-my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
-
 # Get list of component files
 my ($exposures, $command, $success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
@@ -345,5 +349,5 @@
         $command .= " -det_id $det_id";
         $command .= " -iteration $iter";
-	# XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
+        # XXX EAM : we should add this to the db : $command .= " -path_base $outroot";
         $command .= " -code $exit_code";
         $command .= " -dbname $dbname" if defined $dbname;
