Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
August 20, 2003 Again a question | ||||
---|---|---|---|---|
| ||||
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 Re: Again a question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Friedrich Dominicus | 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 Re: Again a question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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 Re: Again a question | ||||
---|---|---|---|---|
| ||||
Posted in reply to Friedrich Dominicus | 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 > |
Copyright © 1999-2021 by the D Language Foundation