Throw std::logic_error if trying to access invalid current control

This commit is contained in:
Joakim Hove 2019-07-01 18:17:27 +02:00 committed by Atgeirr Flø Rasmussen
parent af1bf9a193
commit 9f1e3465db

View File

@ -42,6 +42,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdexcept>
/** /**
* Controls for a single well. * Controls for a single well.
* Each control specifies a well rate or bottom-hole pressure. Only * Each control specifies a well rate or bottom-hole pressure. Only
@ -295,6 +297,8 @@ well_controls_iget_type(const struct WellControls * ctrl, int control_index) {
enum WellControlType enum WellControlType
well_controls_get_current_type(const struct WellControls * ctrl) { well_controls_get_current_type(const struct WellControls * ctrl) {
if (ctrl->current < 0)
throw std::logic_error("Tried to use invalid current control < 0");
return well_controls_iget_type( ctrl , ctrl->current); return well_controls_iget_type( ctrl , ctrl->current);
} }
@ -312,6 +316,8 @@ well_controls_iget_target(const struct WellControls * ctrl, int control_index) {
double double
well_controls_get_current_target(const struct WellControls * ctrl) { well_controls_get_current_target(const struct WellControls * ctrl) {
if (ctrl->current < 0)
throw std::logic_error("Tried to use invalid current control < 0");
return ctrl->target[ctrl->current]; return ctrl->target[ctrl->current];
} }