diff --git a/Assets/UXF/Scripts/Session.cs b/Assets/UXF/Scripts/Session.cs
index 23f66c9a..47e4ddff 100644
--- a/Assets/UXF/Scripts/Session.cs
+++ b/Assets/UXF/Scripts/Session.cs
@@ -618,9 +618,25 @@ Trial GetPrevTrial()
///
///
Trial GetFirstTrial()
- {
- var firstBlock = blocks[0];
- return firstBlock.trials[0];
+ {
+ Block firstBlock;
+ try
+ {
+ firstBlock = blocks[0];
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ throw new NoSuchTrialException("There is no first trial because no blocks have been created!");
+ }
+
+ try
+ {
+ return firstBlock.trials[0];
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ throw new NoSuchTrialException("There is no first trial. No trials exist in the first block.");
+ }
}
///
@@ -629,8 +645,24 @@ Trial GetFirstTrial()
///
Trial GetLastTrial()
{
- var lastBlock = blocks[blocks.Count - 1];
- return lastBlock.trials[lastBlock.trials.Count - 1];
+ Block lastBlock;
+ try
+ {
+ lastBlock = blocks[0];
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ throw new NoSuchTrialException("There is no last trial because no blocks have been created!");
+ }
+
+ try
+ {
+ return lastBlock.trials[lastBlock.trials.Count - 1];
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ throw new NoSuchTrialException("There is no last trial. No trials exist in the last block.");
+ }
}
///
diff --git a/Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs b/Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs
index 2b736a45..239f3a91 100644
--- a/Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs
+++ b/Assets/UXF/Scripts/Tests/Editor/TestSessionBuilding.cs
@@ -129,6 +129,35 @@ public void SwapTrials()
session.blocks = new List();
}
+
+ [Test]
+ public void InvalidTrialAccess()
+ {
+ Block block = session.CreateBlock();
+
+ Assert.Throws(
+ delegate { Trial t = session.FirstTrial; }
+ );
+
+ Assert.Throws(
+ delegate { Trial t = session.LastTrial; }
+ );
+
+ // reset blocks
+ session.blocks = new List();
+ }
+
+ [Test]
+ public void InvalidBlockAccess()
+ {
+ Assert.Throws(
+ delegate { Trial t = session.FirstTrial; }
+ );
+
+ Assert.Throws(
+ delegate { Trial t = session.LastTrial; }
+ );
+ }
}