Переглянути джерело

Compiler-Exceptions: add RethrowErrorHandler

Manfred Kroehnert 11 роки тому
батько
коміт
243e119f15
3 змінених файлів з 53 додано та 0 видалено
  1. 16 0
      js/Compiler-Exceptions.deploy.js
  2. 22 0
      js/Compiler-Exceptions.js
  3. 15 0
      st/Compiler-Exceptions.st

+ 16 - 0
js/Compiler-Exceptions.deploy.js

@@ -112,3 +112,19 @@ smalltalk.UnknownVariableError);
 
 
 
+smalltalk.addClass('RethrowErrorHandler', smalltalk.ErrorHandler, [], 'Compiler-Exceptions');
+smalltalk.addMethod(
+"_handleError_",
+smalltalk.method({
+selector: "handleError:",
+fn: function (anError){
+var self=this;
+smalltalk.send(self,"_handleError_",[anError],smalltalk.ErrorHandler);
+throw anError;
+;
+return self}
+}),
+smalltalk.RethrowErrorHandler);
+
+
+

+ 22 - 0
js/Compiler-Exceptions.js

@@ -159,3 +159,25 @@ smalltalk.UnknownVariableError);
 
 
 
+smalltalk.addClass('RethrowErrorHandler', smalltalk.ErrorHandler, [], 'Compiler-Exceptions');
+smalltalk.RethrowErrorHandler.comment="This class is used in the commandline version of the compiler.\x0aIt uses the handleError: message of ErrorHandler for printing the stacktrace and throws the error again as JS exception.\x0aAs a result Smalltalk errors are not swallowd by the Amber runtime and compilation can be aborted."
+smalltalk.addMethod(
+"_handleError_",
+smalltalk.method({
+selector: "handleError:",
+category: 'error handling',
+fn: function (anError){
+var self=this;
+smalltalk.send(self,"_handleError_",[anError],smalltalk.ErrorHandler);
+throw anError;
+;
+return self},
+args: ["anError"],
+source: "handleError: anError\x0a\x09super handleError: anError.\x0a    <throw anError>",
+messageSends: ["handleError:"],
+referencedClasses: []
+}),
+smalltalk.RethrowErrorHandler);
+
+
+

+ 15 - 0
st/Compiler-Exceptions.st

@@ -85,3 +85,18 @@ variableName: aString
 	variableName := aString
 ! !
 
+ErrorHandler subclass: #RethrowErrorHandler
+	instanceVariableNames: ''
+	package: 'Compiler-Exceptions'!
+!RethrowErrorHandler commentStamp!
+This class is used in the commandline version of the compiler.
+It uses the handleError: message of ErrorHandler for printing the stacktrace and throws the error again as JS exception.
+As a result Smalltalk errors are not swallowd by the Amber runtime and compilation can be aborted.!
+
+!RethrowErrorHandler methodsFor: 'error handling'!
+
+handleError: anError
+	super handleError: anError.
+    <throw anError>
+! !
+