Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17250


Ignore:
Timestamp:
09/13/19 10:02:57 (5 years ago)
Author:
chaider
Message:

#2971 Added exception handling for constraint parser

Location:
branches/2971_named_intervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.cs

    r17249 r17250  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Drawing;
    2324using HeuristicLab.Collections;
    2425using HeuristicLab.Core;
     
    7576      if (constraintsInput.Text != null) {
    7677        intervalConstraints.Clear();
    77         var parsedConstraints = ParseConstraints(constraintsInput.Text);
    78         Content.Constraints = parsedConstraints;
    79         Content.Input = constraintsInput.Text;
    80         errorOutput.Text = "";
     78        try {
     79          var parsedConstraints = ParseConstraints(constraintsInput.Text);
     80          Content.Constraints = parsedConstraints;
     81          Content.Input = constraintsInput.Text;
     82          errorOutput.ForeColor = Color.DarkGreen;
     83          errorOutput.Text = "Constraints successfully parsed.";
     84          //Catch the exception from the constraints parser and show it in the error dialog
     85        } catch(ArgumentException ex) {
     86          Content.Constraints = new List<IntervalConstraint>();
     87          errorOutput.ForeColor = Color.DarkRed;
     88          errorOutput.Text = ex.Message.Replace("Parameter name", "@Line");
     89        }
    8190      } else {
    8291        errorOutput.Text = "No constraints were found!";
     
    125134
    126135    private void constraintsInput_TextChanged(object sender, EventArgs e) {
    127       if (Content.Input != constraintsInput.Text) {
     136      if (Content.Input != constraintsInput.Text) {
     137        errorOutput.ForeColor = Color.DarkOrange;
    128138        errorOutput.Text = "Unparsed changes! Press parse button to save changes.";
    129139        Content.Input = constraintsInput.Text;
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataConstraintView.designer.cs

    r17249 r17250  
    120120      // errorOutput
    121121      //
     122      this.errorOutput.MaximumSize = new Size(350, 0);
    122123      this.errorOutput.AutoSize = true;
    123124      this.errorOutput.ForeColor = Color.DarkRed;
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalConstraintsParser.cs

    r17146 r17250  
    4747          if (match.Success) {
    4848            if (match.Groups.Count != 10) {
    49               throw new ArgumentException("The target-constraint is not complete.");
     49              throw new ArgumentException("The target-constraint is not complete.", line);
    5050            } else {
    5151              var targetVariable = match.Groups[1].Value.Trim();
     
    5555
    5656              if (targetVariable != target) {
    57                 throw new ArgumentException($"The target variable {targetVariable}  does not match the provided target {target}.");
     57                throw new ArgumentException($"The target variable {targetVariable}  does not match the provided target {target}.", line);
    5858              }
    5959
     
    7474            }
    7575          } else {
    76             throw new ArgumentException("The inserted target constraint is not valid.");
     76            throw new ArgumentException("The inserted target constraint is not valid.", line);
    7777          }
    7878          //Check for derivation
     
    8383          if (match.Success) {
    8484            if (match.Groups.Count != 17) {
    85               throw new ArgumentException("The given derivation-constraint is not complete.");
     85              throw new ArgumentException("The given derivation-constraint is not complete.", line);
    8686            } else {
    8787              var derivationTarget = match.Groups[3].Value.Trim();
     
    9696
    9797              if (derivationTarget != target) {
    98                 throw new ArgumentException($"The target variable {derivationTarget}  does not match the provided target {target}.");
     98                throw new ArgumentException($"The target variable {derivationTarget}  does not match the provided target {target}.", line);
    9999              }
    100100
    101101              if (variables.All(v => v != derivationVariable)) {
    102                 throw new ArgumentException($"The given variable {derivationVariable} does not exist in the dataset.");
     102                throw new ArgumentException($"The given variable {derivationVariable} does not exist in the dataset.", line);
    103103              }
    104104
    105105              if (match.Groups[2].Value.Trim() != "" || match.Groups[11].Value.Trim() != "") {
    106106                if (match.Groups[2].Value.Trim() == "" || match.Groups[11].Value.Trim() == "")
    107                   throw new ArgumentException("Number of derivation has to be written on both sides.");
     107                  throw new ArgumentException("Number of derivation has to be written on both sides.", line);
    108108                if (match.Groups[2].Value.Trim() != match.Groups[11].Value.Trim())
    109                   throw new ArgumentException("Derivation number is not equal on both sides.");
     109                  throw new ArgumentException("Derivation number is not equal on both sides.", line);
    110110              }
    111111
     
    126126            }
    127127          } else {
    128             throw new ArgumentException("The inserted derivation constraint is not valid.");
     128            throw new ArgumentException("The inserted derivation constraint is not valid.", line);
    129129          }
    130130          //Check for comment
     
    133133          continue;
    134134        } else {
    135           throw new ArgumentException("Error at your constraints definition constraints have to start with (Target: | d | \u2202 | #)");
     135          throw new ArgumentException("Error at your constraints definition constraints have to start with (Target: | d | \u2202 | #)", line);
    136136        }
    137137      }
Note: See TracChangeset for help on using the changeset viewer.