Index: trunk/ippScripts/scripts/magic_tree.pl
===================================================================
--- trunk/ippScripts/scripts/magic_tree.pl	(revision 20762)
+++ trunk/ippScripts/scripts/magic_tree.pl	(revision 22430)
@@ -31,4 +31,13 @@
 
 use constant MAX_FIELDS => 4;   # Maximum number of fields to be in a node
+
+# Look for programs we need
+my $missing_tools;
+my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
+my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
+if ($missing_tools) {
+    warn("Can't find required tools.");
+    exit($PS_EXIT_CONFIG_ERROR);
+}
 
 # Parse the command-line arguments
@@ -61,16 +70,11 @@
     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], $magic_id, $PS_EXIT_UNKNOWN_ERROR ); };
+
 $ipprc->define_camera($camera);
 
 $ipprc->redirect_output($logfile) if $logfile;
-
-# Look for programs we need
-my $missing_tools;
-my $magictool = can_run('magictool') or (warn "Can't find magictool" and $missing_tools = 1);
-my $warptool = can_run('warptool') or (warn "Can't find warptool" and $missing_tools = 1);
-if ($missing_tools) {
-    warn("Can't find required tools.");
-    exit($PS_EXIT_CONFIG_ERROR);
-}
 
 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
@@ -96,5 +100,5 @@
         &my_die("Unable to parse metadata list", $magic_id, $PS_EXIT_PROG_ERROR);
 
-    # make a hash indexed by skycell_id 
+    # make a hash indexed by skycell_id
     foreach my $warp ( @$warps ) {
         my $skycell_id = $warp->{skycell_id};
@@ -156,9 +160,9 @@
 
     my ($header, $status) = (undef, 0);
-    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status ); 
+    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status );
     &my_die("failed to open skycell file: $skyfileResolved: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
 
     ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
-    
+
     &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
 
@@ -171,5 +175,5 @@
         $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
     } else {
-        # if the skyfile is compressed then the WCS won't be in the primary header, move to the 
+        # if the skyfile is compressed then the WCS won't be in the primary header, move to the
         # extension
         my $hdutype;
@@ -257,5 +261,5 @@
     my $node = shift @tasks;
     divide_node($node, \@tasks);
-} 
+}
 
 ### Format tree for magictool
