Mathematica

Error Handling

You may want to react on error messages created by a called function. For instance if you open a file and it cannot be opened.

Check[expr,failexpr]

evaluates expr, and returns the result, unless messages were generated, in which case it evaluates and returns failexpr.

Check[expr,failexpr,{s1::t1,s2::t2,…}]

checks only for the specified messages.

Check[expr,failexpr,"name"]

checks only for messages in the named message group.

Example:

Check[(a=<<"hallo"); , Print["could not open file"]; Exit[42]; , {Get::noopen}]

QR-Code
QR-Code Mathematica (erstellt für aktuelle Seite)