MyStatement concept should "throw an exception"

  • 1
  • 26

Hi MPS Pros,

when writing throw new Exceptin() in a InstanceMethod,
one get s the errormessage "Error: uncaught Exceptions: Exception"

i have concept MyStatement which extends Statement. The MyStatement can throw an Exception in the generated code. I already checked the code of the ThrowStatement but did not figure out how i can get the errormessage to appear..

Any hints?
Dan

My Code

public boolean isGuardClauseStatement()
overrides Statement.isGuardClauseStatement {
true;
}

public void collectUncaughtMethodThrowables(set<node<Classifier>> throwables, boolean ignoreMayBeThrowables)
overrides Statement.collectUncaughtMethodThrowables {
node<Expression> exp = <new Exception()>;
if (!(ignoreMayBeThrowables)) {
Statement.collectUncaughtMethodThrowables(throwables, exp);
}

throwables.add(exp.type : ClassifierType.classifier);

}
There is a checking rule checkThrowedByThrowIsCaught for the ThrowStatement. At the end you can find this method call: RulesFunctions_BaseLanguage.check(throwables, throwStatement). You simply have to pass a set of exceptions that is thrown by your statement. Everything else if done by this method.

Example:
When your statement throws an IOException, create a checking rule like this:
checking rule check_ThrowIoExcpetion {
  applicable for concept = ThrowIoException as statement
  overrides false

  do {
    set<node<Type>> throwables = new hashset<node<Type>>;
    throwables.add(<IOException>);
    RulesFunctions_BaseLanguage.check(throwables, statement);
  }
}