Skip to content

A Mathematica package to handle errors when calling a function with wrong arguments.

License

Notifications You must be signed in to change notification settings

tgoelles/functionArgumentFailure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

functionArgumentFailure

A Mathematica package to handle errors when calling a function with wrong arguments.

Authors

Thomas Gölles, thomas.goelles@atseda.com

Introduction

The Wolfram Language is a bit special in the way it handles functions which have been called with wrong arguments. Most built-in functions will give a message and return unevaluated when the arguments are not correct.

I was looking for a better solution which gives me more feedback and makes debugging easier. Therefore, I created the functionArgumentFailure package. Whenever a function is called with wrong arguments a FailureObject is returned and added to the global "failurelist". Each FailureObject informs where the error occurred and the reason for it.

In version 10 the FailureObject has been introduced, and the Function FailureQ has been added in version 10.2. The FailureObject is not often used in the internal function but I think it is ideal for error handling.

The package is compatible and tested with version 12.

Installation

In Mathematica go to File > Install ... and install the package.

Basic Usage

Needs["functionArgumentFailure`"]

ClearAll[test];

test[a_?StringQ] := 1;
test[args___] := functionArgumentFailure[test, args];

So whenever the pattern of test["some string"] is not matched the functionArgumentFailure is called with 2 arguments. First the name of the failed function and second the arguments. Make sure to use 3 _ for the pattern test, as this allows zero or more arguments.

Here is an example where the function test has been called with not enough arguments:

Failure Example

For further information see Examples.nb and the unit tests in tests/Test.nb

More Info:

FailureQ documentation

FailureObject documentation

An interresting discussion on stackexchange

About

A Mathematica package to handle errors when calling a function with wrong arguments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published