From 954f0b760667660c4324f91125416c5f2e17dfa2 Mon Sep 17 00:00:00 2001
From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com>
Date: Mon, 7 Feb 2022 13:40:07 +0100
Subject: [PATCH] Users may not give dt < 0. (#1821)

* Users may not give dt < 0 to simulation.run()
* Add and throw domain_error.
---
 arbor/arbexcept.cpp               | 2 ++
 arbor/include/arbor/arbexcept.hpp | 7 +++++++
 arbor/simulation.cpp              | 3 +++
 3 files changed, 12 insertions(+)

diff --git a/arbor/arbexcept.cpp b/arbor/arbexcept.cpp
index 50ac0968..37cb7a92 100644
--- a/arbor/arbexcept.cpp
+++ b/arbor/arbexcept.cpp
@@ -10,6 +10,8 @@ namespace arb {
 
 using arb::util::pprintf;
 
+domain_error::domain_error(const std::string& w): arbor_exception(w) {}
+
 bad_cell_probe::bad_cell_probe(cell_kind kind, cell_gid_type gid):
     arbor_exception(pprintf("recipe::get_grobe() is not supported for cell with gid {} of kind {})", gid, kind)),
     gid(gid),
diff --git a/arbor/include/arbor/arbexcept.hpp b/arbor/include/arbor/arbexcept.hpp
index 4a06571b..2574c71f 100644
--- a/arbor/include/arbor/arbexcept.hpp
+++ b/arbor/include/arbor/arbexcept.hpp
@@ -28,6 +28,13 @@ struct arbor_exception: std::runtime_error {
     {}
 };
 
+// Logic errors
+
+// Argument violates domain constraints, eg ln(-1)
+struct domain_error: arbor_exception {
+    domain_error(const std::string&);
+};
+
 // Recipe errors:
 
 struct bad_cell_probe: arbor_exception {
diff --git a/arbor/simulation.cpp b/arbor/simulation.cpp
index daa22c3e..300b9947 100644
--- a/arbor/simulation.cpp
+++ b/arbor/simulation.cpp
@@ -514,6 +514,9 @@ void simulation::reset() {
 }
 
 time_type simulation::run(time_type tfinal, time_type dt) {
+    if (dt <= 0.0) {
+        throw domain_error("Finite time-step must be supplied.");
+    }
     return impl_->run(tfinal, dt);
 }
 
-- 
GitLab