@@ -18,7 +18,7 @@ GenericFunction.prototype.lastMatchCallResolver = function (matchingMethods, met
18
18
if ( matchingMethods . length >= 1 ) {
19
19
return matchingMethods [ matchingMethods . length - 1 ] . executor . apply ( methodCallContext , methodCallArgs )
20
20
} else {
21
- throw new ReferenceError ( "call to generic function with docstring '" + this . docstring + "': no matching method found for the arguments " + methodCallArgs . toString ( ) )
21
+ throw new NoMatchingMethodError ( this . docstring , methodCallArgs )
22
22
}
23
23
}
24
24
@@ -31,7 +31,7 @@ GenericFunction.prototype.warningCallResolver = function (matchingMethods, metho
31
31
32
32
GenericFunction . prototype . strictCallResolver = function ( matchingMethods , methodCallContext , methodCallArgs ) {
33
33
if ( matchingMethods . length > 1 ) {
34
- throw new RangeError ( "generic function does not have discreetely partitioned domain, multiple methods match the given arguments " + methodCallArgs . toString ( ) )
34
+ throw new MultipleMatchingMethodsError ( this . docstring , methodCallArgs )
35
35
} else {
36
36
return this . lastMatchCallResolver ( matchingMethods , methodCallContext , methodCallArgs )
37
37
}
@@ -64,4 +64,40 @@ var defgeneric = function (docstring, callResolverIdentifier) {
64
64
} )
65
65
}
66
66
67
- module . exports = defgeneric
67
+ var NoMatchingMethodError = function ( docstring , args , errObj ) {
68
+ Object . assign (
69
+ this ,
70
+ errObj ? errObj : new Error ( ) , //for properties like stacktrace etc
71
+ {
72
+ name : "generic functions: no matching method error" ,
73
+ message : "call to generic function failed, no matching method found. Please see .docstring and .args properties of this error for more details" ,
74
+ docstring : docstring ,
75
+ offendingArguments : args
76
+ }
77
+ )
78
+ }
79
+
80
+ NoMatchingMethodError . prototype = Object . create ( Error . prototype )
81
+ NoMatchingMethodError . prototype . constructor = NoMatchingMethodError
82
+
83
+ var MultipleMatchingMethodsError = function ( docstring , args ) {
84
+ Object . assign (
85
+ this ,
86
+ errObj ? errObj : new Error ( ) , //for properties like stacktrace etc
87
+ {
88
+ name : "generic functions: multiple matching methods error" ,
89
+ message : "generic function does not have discreetely partitioned domain, multiple methods match the given arguments " ,
90
+ docstring : docstring ,
91
+ offendingArguments : args
92
+ }
93
+ )
94
+ }
95
+
96
+ MultipleMatchingMethodsError . prototype = Object . create ( Error . prototype )
97
+ MultipleMatchingMethodsError . prototype . constructor = MultipleMatchingMethodsError
98
+
99
+ module . exports = {
100
+ defgeneric,
101
+ NoMatchingMethodError,
102
+ MultipleMatchingMethodsError
103
+ }
0 commit comments