Raise NoModificationError
authorStefan Vogel <sv@exept.de>
Thu, 05 Nov 2009 18:37:53 +0100
changeset 12491 d74b78dd478a
parent 12490 17e8101ce634
child 12492 d63fd473f6e7
Raise NoModificationError
ImmutableString.st
--- a/ImmutableString.st	Thu Nov 05 18:37:27 2009 +0100
+++ b/ImmutableString.st	Thu Nov 05 18:37:53 2009 +0100
@@ -76,23 +76,23 @@
 
 !ImmutableString methodsFor:'accessing'!
 
-at:index put:value
+at:index put:value 
     "Trigger an error if an immutable string is stored into.
      The store will be performed (for compatibility reasons) if you continue
      in the debugger."
-
-    self notifyStoreError.
+    
+    self noModificationError.
     ^ super at:index put:value
 
     "Created: / 3.8.1998 / 14:45:14 / cg"
 !
 
-basicAt:index put:value
+basicAt:index put:value 
     "Trigger an error if an immutable string is stored into.
      The store will be performed (for compatibility reasons) if you continue
      in the debugger."
-
-    self notifyStoreError.
+    
+    self noModificationError.
     ^ super basicAt:index put:value
 ! !
 
@@ -154,7 +154,9 @@
 !ImmutableString methodsFor:'error handling'!
 
 creator 
-    "find the method that contains me"
+    "find the method that contains me.
+     This works only, if the string is included in a method's literal array.
+     Stc compiled code does not put strings into the literal array - Bytecode compiled code does."
 
     ^ Method allSubInstances detect:[:aMethod | (aMethod referencesGlobal:self)] ifNone:nil.
 
@@ -165,25 +167,28 @@
     "Created: / 3.8.1998 / 14:47:19 / cg"
 !
 
-notifyStoreError
+noModificationError
     "a store is attempted - for our convenience, find the method that
      contains me, for a nicer error message"
-
-    |creator msg|
+    
+    |creator msg context|
 
     creator := self creator.
-    msg := 'store into/change of literal'.
     creator notNil ifTrue:[
-        msg := msg , ' (' , creator whoString , ')'
+        msg := ' (' , creator whoString , ')'
     ].
-    "
+    context := thisContext sender.
+     "
      this error is reported on an attempt to store into a literal
      string. The literal was created in creator.
      If you press continue in the debugger, the store will be performed.
      If you don't want this, press abort and check your code.
      Storing into literals is VERY VERY bad coding style.
     "
-    self error:msg mayProceed:true
+    NoModificationError 
+        raiseRequestWith:self
+        errorString:msg
+        in:context.
 
     "Created: / 3.8.1998 / 14:47:45 / cg"
 ! !
@@ -200,11 +205,11 @@
 
 !ImmutableString methodsFor:'specials'!
 
-become:anotherObject
+become:anotherObject 
     "trigger an error if I should become something else
      (this would be an even more tricky manipulation)"
-
-    self notifyStoreError.
+    
+    self noModificationError.
     ^ super become:anotherObject
 
     "Created: / 3.8.1998 / 14:48:29 / cg"
@@ -213,8 +218,8 @@
 becomeNil
     "trigger an error if I should become nil
      (this would be an even more tricky manipulation)"
-
-    self notifyStoreError.
+    
+    self noModificationError.
     ^ super becomeNil
 
     "Created: / 3.8.1998 / 14:48:37 / cg"
@@ -223,9 +228,9 @@
 !ImmutableString class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ImmutableString.st,v 1.7 2009-11-05 14:42:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ImmutableString.st,v 1.8 2009-11-05 17:37:53 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ImmutableString.st,v 1.7 2009-11-05 14:42:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ImmutableString.st,v 1.8 2009-11-05 17:37:53 stefan Exp $'
 ! !