2
0

Kernel-Exceptions.st 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. Smalltalk createPackage: 'Kernel-Exceptions'!
  2. Object subclass: #Error
  3. instanceVariableNames: 'messageText'
  4. package: 'Kernel-Exceptions'!
  5. !Error commentStamp!
  6. From the ANSI standard:
  7. This protocol describes the behavior of instances of class `Error`.
  8. These are used to represent error conditions that prevent the normal continuation of processing.
  9. Actual error exceptions used by an application may be subclasses of this class.
  10. As `Error` is explicitly specified to be subclassable, conforming implementations must implement its behavior in a non-fragile manner.!
  11. !Error methodsFor: 'accessing'!
  12. beHandled
  13. <self.amberHandled = true>
  14. !
  15. beUnhandled
  16. <self.amberHandled = false>
  17. !
  18. context
  19. <return self.context>
  20. !
  21. jsStack
  22. <return self.stack>
  23. !
  24. messageText
  25. ^ messageText
  26. !
  27. messageText: aString
  28. messageText := aString
  29. !
  30. signalerContext
  31. ^ self signalerContextFrom: self context
  32. !
  33. signalerContextFrom: aContext
  34. "Find the first sender of signal(:), the first context which is neither
  35. for an instance method nor for a class side method of Exception (or subclass).
  36. This will make sure that the same context is found for both, `Error signal`
  37. and `Error new signal`"
  38. ^ aContext findContextSuchThat: [ :context |
  39. (context receiver == self
  40. or: [ context receiver == self class ]) not ]
  41. ! !
  42. !Error methodsFor: 'initialization'!
  43. initialize
  44. self messageText: 'Errorclass: ', (self class name).
  45. ! !
  46. !Error methodsFor: 'signaling'!
  47. resignal
  48. "Resignal the receiver without changing its exception context"
  49. <
  50. self.amberHandled = false;
  51. throw(self);
  52. >
  53. !
  54. signal
  55. <
  56. self.amberHandled = false;
  57. self.context = smalltalk.getThisContext();
  58. self.smalltalkError = true; throw(self)
  59. >
  60. !
  61. signal: aString
  62. self messageText: aString.
  63. self signal
  64. ! !
  65. !Error methodsFor: 'testing'!
  66. isSmalltalkError
  67. <return self.smalltalkError === true>
  68. !
  69. wasHandled
  70. <return self.amberHandled || false>
  71. ! !
  72. !Error class methodsFor: 'helios'!
  73. heliosClass
  74. ^ 'exception'
  75. ! !
  76. !Error class methodsFor: 'instance creation'!
  77. signal
  78. ^ self new signal
  79. !
  80. signal: aString
  81. ^ self new
  82. signal: aString
  83. ! !
  84. Error subclass: #Halt
  85. instanceVariableNames: ''
  86. package: 'Kernel-Exceptions'!
  87. !Halt commentStamp!
  88. I am provided to support `Object>>#halt`.!
  89. !Halt methodsFor: 'accessing'!
  90. messageText
  91. ^ 'Halt encountered'
  92. !
  93. signalerContextFrom: aContext
  94. "specialized version to find the proper context to open the debugger on.
  95. This will find the first context whose method is no longer on `Halt` or
  96. `Halt class` nor is `#halt` method itself."
  97. ^ aContext findContextSuchThat: [ :context |
  98. (context receiver == self
  99. or: [ (context receiver == self class)
  100. or: [ context method selector = #halt ]]) not ]
  101. ! !
  102. Error subclass: #JavaScriptException
  103. instanceVariableNames: 'exception'
  104. package: 'Kernel-Exceptions'!
  105. !JavaScriptException commentStamp!
  106. A JavaScriptException is thrown when a non-Smalltalk exception occurs while in the Smalltalk stack.
  107. See `boot.js` `inContext()` and `BlockClosure >> on:do:`!
  108. !JavaScriptException methodsFor: 'accessing'!
  109. context: aMethodContext
  110. "Set the context from the outside.
  111. See boot.js `inContext()` exception handling"
  112. <self.context = aMethodContext>
  113. !
  114. exception
  115. ^ exception
  116. !
  117. exception: anException
  118. exception := anException
  119. !
  120. messageText
  121. <return 'JavaScript exception: ' + self["@exception"].toString()>
  122. ! !
  123. !JavaScriptException class methodsFor: 'instance creation'!
  124. on: anException
  125. ^ self new
  126. exception: anException;
  127. yourself
  128. !
  129. on: anException context: aMethodContext
  130. ^ self new
  131. exception: anException;
  132. context: aMethodContext;
  133. yourself
  134. ! !
  135. Error subclass: #MessageNotUnderstood
  136. instanceVariableNames: 'message receiver'
  137. package: 'Kernel-Exceptions'!
  138. !MessageNotUnderstood commentStamp!
  139. This exception is provided to support `Object>>doesNotUnderstand:`.!
  140. !MessageNotUnderstood methodsFor: 'accessing'!
  141. message
  142. ^ message
  143. !
  144. message: aMessage
  145. message := aMessage
  146. !
  147. messageText
  148. ^ self receiver asString, ' does not understand #', self message selector
  149. !
  150. receiver
  151. ^ receiver
  152. !
  153. receiver: anObject
  154. receiver := anObject
  155. ! !
  156. Error subclass: #NonBooleanReceiver
  157. instanceVariableNames: 'object'
  158. package: 'Kernel-Exceptions'!
  159. !NonBooleanReceiver commentStamp!
  160. NonBooleanReceiver exceptions may be thrown when executing inlined methods such as `#ifTrue:` with a non boolean receiver.!
  161. !NonBooleanReceiver methodsFor: 'accessing'!
  162. object
  163. ^ object
  164. !
  165. object: anObject
  166. object := anObject
  167. ! !
  168. Error subclass: #PackageCommitError
  169. instanceVariableNames: ''
  170. package: 'Kernel-Exceptions'!
  171. !PackageCommitError commentStamp!
  172. I get signaled when an attempt to commit a package has failed.!