check assertions - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Debugging : ASSERT

ASSERT - check assertions

Calling Sequence

ASSERT(cond, string)

ASSERT(cond)

Parameters

cond

-

expression evaluating to true or false

string

-

string

Description

• 

ASSERT is used to guarantee pre- and post-conditions while a Maple procedure is executing.

• 

If the first argument evaluates to false, an error is generated and the second argument is printed in order to identify the nature of the failure. Such an error cannot be trapped via try-catch.

• 

If the first argument evaluates to true, ASSERT returns NULL.

• 

The ASSERT mechanism can be turned on and off with kernelopts. If turned off, the overhead of processing an ASSERT is negligible.

Thread Safety

• 

The ASSERT command is thread-safe as of Maple 15.

• 

For more information on thread safety, see index/threadsafe.

Examples

Query the current state.

kerneloptsassertlevel

0

(1)

Turn assertions on (kernelopts returns its previous value).

kerneloptsassertlevel=1

0

(2)

The following results in assertion failures.

ASSERTtypex,integer,x must be an integer

Error, assertion failed, x must be an integer

a:=1&colon;ASSERT5<a&comma;cata is too small: &comma;a

Error, assertion failed, a is too small: 1

This assertion check will succeed.

ASSERTtrue&comma;This is ok

Assertion failures are not trappable.

tryASSERTfalsecatch&colon;end try

Turn assertions off (the previous value is returned again).

kerneloptsassertlevel&equals;0

1

(3)

Now assertion failures are ignored.

ASSERTtypex&comma;integer&comma;x must be an integer

See Also

kernelopts, try


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam