www.digitalmars.com         C & C++   DMDScript  

D - Again a question

reply Friedrich Dominicus <frido q-software-solutions.com> writes:
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
Aug 20 2003
parent reply "Walter" <walter digitalmars.com> writes:
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
Aug 23 2003
parent reply Friedrich Dominicus <frido q-software-solutions.com> writes:
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
Aug 24 2003
parent reply "Walter" <walter digitalmars.com> writes:
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
Aug 28 2003
parent "Vathix" <vathix dprogramming.com> writes:
Also, I think toString() for an assert exception should return what print()
displays and not "Object" :)
Aug 31 2003