From 53494ccbd1a97d5de885c36151b02a66999c4847 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Thu, 6 Oct 2011 19:35:40 +0200 Subject: Errors.m: Add ErrorDefinition This function can be used to create default definitions for functions which throw exceptions indicating unexpected arguments have been passed. --- Tools/MathematicaMisc/Errors.m | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Tools/MathematicaMisc') diff --git a/Tools/MathematicaMisc/Errors.m b/Tools/MathematicaMisc/Errors.m index 4de9a65..2f0d6cd 100644 --- a/Tools/MathematicaMisc/Errors.m +++ b/Tools/MathematicaMisc/Errors.m @@ -9,6 +9,7 @@ VerifyStringList; VerifyList; InfoMessage; SetDebugLevel; +ErrorDefinition::usage = "ErrorDefinition[f] creates a default definition of a function f which throws an exception. This can be used to catch programming errors where f is called with incorrect arguments."; DebugQuiet = 0; Warnings = 1 @@ -88,6 +89,10 @@ InfoMessage[level_, message__] := SetDebugLevel[level_] := debugLevel = level; +ErrorDefinition[x_] := + x[args___] := + ThrowError["Invalid arguments to "<>ToString[x], {args}//FullForm]; + End[]; EndPackage[]; -- cgit v1.2.3