diff --git a/creatur.cabal b/creatur.cabal
--- a/creatur.cabal
+++ b/creatur.cabal
@@ -1,5 +1,5 @@
 Name:              creatur
-Version:           5.2.0
+Version:           5.2.1
 Stability:         experimental
 Synopsis:          Framework for artificial life experiments.
 Description:       A software framework for automating experiments
@@ -35,7 +35,7 @@
 source-repository this
   type:     git
   location: https://github.com/mhwombat/creatur.git
-  tag:      5.0.1
+  tag:      5.2.1
 
 library
   GHC-Options:      -Wall -fno-warn-orphans
diff --git a/src/ALife/Creatur/Task.hs b/src/ALife/Creatur/Task.hs
--- a/src/ALife/Creatur/Task.hs
+++ b/src/ALife/Creatur/Task.hs
@@ -69,8 +69,9 @@
 runNoninteractingAgents agentProgram summaryProgram = do
   atEndOfRound summaryProgram
   (a:_) <- lineup
-  withAgent agentProgram a
   markDone a
+    -- do this first in case the next line triggers an exception
+  withAgent agentProgram a
 
 --   The input parameter is a list of agents. The first agent in the
 --   list is the agent whose turn it is to use the CPU. The rest of
@@ -87,8 +88,9 @@
 runInteractingAgents agentsProgram summaryProgram = do
   atEndOfRound summaryProgram
   as <- lineup
-  withAgents agentsProgram as
   when (not $ null as) $ markDone (head as)
+    -- do this first in case the next line triggers an exception
+  withAgents agentsProgram as
 
 atEndOfRound
   :: Universe u 
