2 classvar <>handling = false;
3 classvar <>debug = false;
4 classvar <>inProtectedFunction = false;
6 var <>what, <>protectedBacktrace, <>path;
9 var protectedBacktrace, instance;
10 if (debug || inProtectedFunction, {
11 protectedBacktrace = this.getBackTrace.caller;
12 inProtectedFunction = false;
14 ^super.newCopyArgs(what ? this.name, protectedBacktrace, thisProcess.nowExecutingPath);
17 ^"EXCEPTION: " ++ what
20 this.errorString.postln;
21 if(protectedBacktrace.notNil, { this.postProtectedBacktrace });
23 this.adviceLink.postln;
26 ^("For advice: [http://supercollider.sf.net/wiki/index.php/%]"
27 .format(this.adviceLinkPage));
30 ^this.errorString.tr($ , $_).tr($\n, $_);
32 postProtectedBacktrace {
33 var out, currentFrame, def, ownerClass, methodName, pos = 0;
35 "\nPROTECTED CALL STACK:".postln;
36 currentFrame = protectedBacktrace;
37 while({currentFrame.notNil}, {
38 def = currentFrame.functionDef;
39 if(def.isKindOf(Method), {
40 ownerClass = def.ownerClass;
41 methodName = def.name;
42 if(ownerClass == Function && (methodName == 'protect'), {
45 out << "\t%:%\t%\n".format(ownerClass, methodName, currentFrame.address);
47 out << "\ta FunctionDef\t%\n".format(currentFrame.address);
48 out << "\t\tsourceCode = %\n".format(def.sourceCode ? "<an open Function>");
50 def.argNames.do({|name, i|
51 out << "\t\targ % = %\n".format(name, currentFrame.args[i]);
53 def.varNames.do({|name, i|
54 out << "\t\targ % = %\n".format(name, currentFrame.args[i]);
56 currentFrame = currentFrame.caller;
58 // lose everything after the last Function:protect
59 // it just duplicates the normal stack with less info
60 out.collection.copyFromStart(pos).postln;
71 ^if(path.isNil) { "" } { "PATH:" + path ++ "\n" }
78 *new { arg what, receiver;
79 ^super.new(what).receiver_(receiver)
82 this.errorString.postln;
85 this.errorPathString.post;
86 if(protectedBacktrace.notNil, { this.postProtectedBacktrace });
88 this.adviceLink.postln;
96 PrimitiveFailedError : MethodError {
97 var <>failedPrimitiveName;
100 ^super.new(Thread.primitiveErrorString, receiver)
101 .failedPrimitiveName_(thisThread.failedPrimitiveName)
104 ^"ERROR: Primitive '%' failed.\n%".format(failedPrimitiveName, what ? "")
108 SubclassResponsibilityError : MethodError {
109 var <>method, <>class;
110 *new { arg receiver, method, class;
111 ^super.new(nil, receiver).method_(method).class_(class)
114 ^"ERROR: '" ++ method.name ++ "' should have been implemented by "
119 ShouldNotImplementError : MethodError {
120 var <>method, <>class;
121 *new { arg receiver, method, class;
122 ^super.new(nil, receiver).method_(method).class_(class)
125 ^"ERROR: '" ++ method.ownerClass.name ++ "-" ++ method.name
126 ++ "' Message not valid for this subclass: "
131 DoesNotUnderstandError : MethodError {
132 var <>selector, <>args;
133 *new { arg receiver, selector, args;
134 ^super.new(nil, receiver).selector_(selector).args_(args)
137 ^"ERROR: Message '" ++ selector ++ "' not understood."
140 this.errorString.postln;
145 this.errorPathString.post;
146 if(protectedBacktrace.notNil, { this.postProtectedBacktrace });
148 this.adviceLink.postln;
151 ^"%#%".format(this.class.name, selector)
156 MustBeBooleanError : MethodError {
158 ^"ERROR: Non Boolean in test."
162 NotYetImplementedError : MethodError {
165 OutOfContextReturnError : MethodError {
166 var <>method, <>result;
167 *new { arg receiver, method, result;
168 ^super.new(nil, receiver).method_(method).result_(result)
171 ^"ERROR: '" ++ method.ownerClass.name ++ "-" ++ method.name
172 ++ "' Out of context return of value: " ++ result
176 ImmutableError : MethodError {
178 *new { arg receiver, value;
179 ^super.new(nil, receiver).value_(value)
182 ^"ERROR: Object is immutable: " ++ receiver
186 BinaryOpFailureError : DoesNotUnderstandError {
188 ^"ERROR: binary operator '" ++ selector ++ "' failed."
192 DeprecatedError : MethodError {
193 var <>method, <>class, <>alternateMethod;
195 *new { arg receiver, method, alternateMethod, class;
196 ^super.new(nil).receiver_(receiver).method_(method).class_(class).alternateMethod_(alternateMethod)
199 var methodSignature = { arg m;
200 var c = m.ownerClass;
201 var str = c.name.asString;
203 { str = str.drop( str.indexOf($_) + 1 ) ++ ":*" ++ m.name }
204 { str = str ++ ":-" ++ m.name };
208 string = "WARNING: Method" + methodSignature.value(method) + "is deprecated and will be removed.";
209 if(alternateMethod.notNil, {
210 string = string + "Use" + methodSignature.value(alternateMethod) + "instead.";
216 this.errorString.postln;
217 this.errorPathString.post;
218 this.adviceLink.postln;
222 Error.handling = true;
225 if(protectedBacktrace.notNil, { this.postProtectedBacktrace });
227 Error.handling = false;
230 Error.handling = false;