Kernel-Exceptions.st 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 = $core.getThisContext();
  58. self.smalltalkError = true;
  59. throw self;
  60. >
  61. !
  62. signal: aString
  63. self messageText: aString.
  64. self signal
  65. ! !
  66. !Error methodsFor: 'testing'!
  67. isSmalltalkError
  68. <return self.smalltalkError === true>
  69. !
  70. wasHandled
  71. <return self.amberHandled || false>
  72. ! !
  73. !Error class methodsFor: 'helios'!
  74. heliosClass
  75. ^ 'exception'
  76. ! !
  77. !Error class methodsFor: 'instance creation'!
  78. signal
  79. ^ self new signal
  80. !
  81. signal: aString
  82. ^ self new
  83. signal: aString
  84. ! !
  85. Error subclass: #Halt
  86. instanceVariableNames: ''
  87. package: 'Kernel-Exceptions'!
  88. !Halt commentStamp!
  89. I am provided to support `Object>>#halt`.!
  90. !Halt methodsFor: 'accessing'!
  91. messageText
  92. ^ 'Halt encountered'
  93. !
  94. signalerContextFrom: aContext
  95. "specialized version to find the proper context to open the debugger on.
  96. This will find the first context whose method is no longer on `Halt` or
  97. `Halt class` nor is `#halt` method itself."
  98. ^ aContext findContextSuchThat: [ :context |
  99. (context receiver == self
  100. or: [ (context receiver == self class)
  101. or: [ context method selector = #halt ]]) not ]
  102. ! !
  103. Error subclass: #JavaScriptException
  104. instanceVariableNames: 'exception'
  105. package: 'Kernel-Exceptions'!
  106. !JavaScriptException commentStamp!
  107. A JavaScriptException is thrown when a non-Smalltalk exception occurs while in the Smalltalk stack.
  108. See `boot.js` `inContext()` and `BlockClosure >> on:do:`!
  109. !JavaScriptException methodsFor: 'accessing'!
  110. context: aMethodContext
  111. "Set the context from the outside.
  112. See boot.js `inContext()` exception handling"
  113. <self.context = aMethodContext>
  114. !
  115. exception
  116. ^ exception
  117. !
  118. exception: anException
  119. exception := anException
  120. !
  121. messageText
  122. <return 'JavaScript exception: ' + self["@exception"].toString()>
  123. ! !
  124. !JavaScriptException class methodsFor: 'instance creation'!
  125. on: anException
  126. ^ self new
  127. exception: anException;
  128. yourself
  129. !
  130. on: anException context: aMethodContext
  131. ^ self new
  132. exception: anException;
  133. context: aMethodContext;
  134. yourself
  135. ! !
  136. Error subclass: #MessageNotUnderstood
  137. instanceVariableNames: 'message receiver'
  138. package: 'Kernel-Exceptions'!
  139. !MessageNotUnderstood commentStamp!
  140. This exception is provided to support `Object>>doesNotUnderstand:`.!
  141. !MessageNotUnderstood methodsFor: 'accessing'!
  142. message
  143. ^ message
  144. !
  145. message: aMessage
  146. message := aMessage
  147. !
  148. messageText
  149. ^ self receiver asString, ' does not understand #', self message selector
  150. !
  151. receiver
  152. ^ receiver
  153. !
  154. receiver: anObject
  155. receiver := anObject
  156. ! !
  157. Error subclass: #NonBooleanReceiver
  158. instanceVariableNames: 'object'
  159. package: 'Kernel-Exceptions'!
  160. !NonBooleanReceiver commentStamp!
  161. NonBooleanReceiver exceptions may be thrown when executing inlined methods such as `#ifTrue:` with a non boolean receiver.!
  162. !NonBooleanReceiver methodsFor: 'accessing'!
  163. object
  164. ^ object
  165. !
  166. object: anObject
  167. object := anObject
  168. ! !
  169. Error subclass: #PackageCommitError
  170. instanceVariableNames: ''
  171. package: 'Kernel-Exceptions'!
  172. !PackageCommitError commentStamp!
  173. I get signaled when an attempt to commit a package has failed.!