Kernel-Exceptions.st 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. !Error methodsFor: 'initialization'!
  31. initialize
  32. self messageText: 'Errorclass: ', (self class name).
  33. ! !
  34. !Error methodsFor: 'signaling'!
  35. resignal
  36. "Resignal the receiver without changing its exception context"
  37. <
  38. self.amberHandled = false;
  39. throw(self);
  40. >
  41. !
  42. signal
  43. <
  44. self.amberHandled = false;
  45. self.context = smalltalk.getThisContext();
  46. self.smalltalkError = true; throw(self)
  47. >
  48. !
  49. signal: aString
  50. self messageText: aString.
  51. self signal
  52. ! !
  53. !Error methodsFor: 'testing'!
  54. isSmalltalkError
  55. <return self.smalltalkError === true>
  56. !
  57. wasHandled
  58. <return self.amberHandled || false>
  59. ! !
  60. !Error class methodsFor: 'helios'!
  61. heliosClass
  62. ^ 'exception'
  63. ! !
  64. !Error class methodsFor: 'instance creation'!
  65. signal
  66. ^ self new signal
  67. !
  68. signal: aString
  69. ^ self new
  70. signal: aString
  71. ! !
  72. Error subclass: #JavaScriptException
  73. instanceVariableNames: 'exception'
  74. package: 'Kernel-Exceptions'!
  75. !JavaScriptException commentStamp!
  76. A JavaScriptException is thrown when a non-Smalltalk exception occurs while in the Smalltalk stack.
  77. See `boot.js` `inContext()` and `BlockClosure >> on:do:`!
  78. !JavaScriptException methodsFor: 'accessing'!
  79. context: aMethodContext
  80. "Set the context from the outside.
  81. See boot.js `inContext()` exception handling"
  82. <self.context = aMethodContext>
  83. !
  84. exception
  85. ^ exception
  86. !
  87. exception: anException
  88. exception := anException
  89. !
  90. messageText
  91. <return 'JavaScript exception: ' + self["@exception"].toString()>
  92. ! !
  93. !JavaScriptException class methodsFor: 'instance creation'!
  94. on: anException
  95. ^ self new
  96. exception: anException;
  97. yourself
  98. !
  99. on: anException context: aMethodContext
  100. ^ self new
  101. exception: anException;
  102. context: aMethodContext;
  103. yourself
  104. ! !
  105. Error subclass: #MessageNotUnderstood
  106. instanceVariableNames: 'message receiver'
  107. package: 'Kernel-Exceptions'!
  108. !MessageNotUnderstood commentStamp!
  109. This exception is provided to support `Object>>doesNotUnderstand:`.!
  110. !MessageNotUnderstood methodsFor: 'accessing'!
  111. message
  112. ^ message
  113. !
  114. message: aMessage
  115. message := aMessage
  116. !
  117. messageText
  118. ^ self receiver asString, ' does not understand #', self message selector
  119. !
  120. receiver
  121. ^ receiver
  122. !
  123. receiver: anObject
  124. receiver := anObject
  125. ! !
  126. Error subclass: #NonBooleanReceiver
  127. instanceVariableNames: 'object'
  128. package: 'Kernel-Exceptions'!
  129. !NonBooleanReceiver commentStamp!
  130. NonBooleanReceiver exceptions may be thrown when executing inlined methods such as `#ifTrue:` with a non boolean receiver.!
  131. !NonBooleanReceiver methodsFor: 'accessing'!
  132. object
  133. ^ object
  134. !
  135. object: anObject
  136. object := anObject
  137. ! !
  138. Error subclass: #PackageCommitError
  139. instanceVariableNames: ''
  140. package: 'Kernel-Exceptions'!
  141. !PackageCommitError commentStamp!
  142. I get signaled when an attempt to commit a package has failed.!