Thread overview
Again a question
Aug 24, 2003
Walter
Aug 28, 2003
Walter
Re: Again a question (assert)
Aug 31, 2003
Vathix
August 20, 2003
Where's AssertException defined? I checked all the sources looked into the static library but did not found it. How do I catch contract violations than?

Regards
Friedrich

August 24, 2003
Actually, it throws an Assert in assert.d, not AssertException.

"Friedrich Dominicus" <frido@q-software-solutions.com> wrote in message news:bhvnbo$1u8n$1@digitaldaemon.com...
> Where's AssertException defined? I checked all the sources looked into the static library but did not found it. How do I catch contract violations than?
>
> Regards
> Friedrich
>


August 25, 2003
Walter wrote:
> Actually, it throws an Assert in assert.d, not AssertException.

Ok if it throws an Assert, why is Assert than defined this way:
class Assert : Object
{
  private:

    uint linnum;
    char[] filename;

    this(char[] filename, uint linnum)
    {
	this.linnum = linnum;
	this.filename = filename

Shouldn't it be derived from either Error or Exception. How do I have to write a function which catches an Assert violation?

This does not work:
double test_1 (double a, double b)
     in {
  assert(! (feq(b, 0.0)));
}
out (result) {
  assert(feq(result, a / b));
}
body {
  return  a / b;
}

int main (){
    puts("Example for catching a contract violation");
    fflush(stdout);
    try {
      double result = test_1(10.0, 0.0);
    }
    catch (Assert a){
        printf("You violated a preconditon of test_1\n");
    }

....


Regards
Friedrich

August 28, 2003
You're right, I need to fix this. -Walter

"Friedrich Dominicus" <frido@q-software-solutions.com> wrote in message news:bicbn3$2lmd$1@digitaldaemon.com...
> Walter wrote:
> > Actually, it throws an Assert in assert.d, not AssertException.
>
> Ok if it throws an Assert, why is Assert than defined this way:
> class Assert : Object
> {
>    private:
>
>      uint linnum;
>      char[] filename;
>
>      this(char[] filename, uint linnum)
>      {
> this.linnum = linnum;
> this.filename = filename
>
> Shouldn't it be derived from either Error or Exception. How do I have to write a function which catches an Assert violation?
>
> This does not work:
> double test_1 (double a, double b)
>       in {
>    assert(! (feq(b, 0.0)));
> }
> out (result) {
>    assert(feq(result, a / b));
> }
> body {
>    return  a / b;
> }
>
> int main (){
>      puts("Example for catching a contract violation");
>      fflush(stdout);
>      try {
>        double result = test_1(10.0, 0.0);
>      }
>      catch (Assert a){
>          printf("You violated a preconditon of test_1\n");
>      }
>
> ....
>
>
> Regards
> Friedrich
>


August 31, 2003
Also, I think toString() for an assert exception should return what print()
displays and not "Object" :)