Kernel-Exceptions.st 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. context
  13. <return self.context>
  14. !
  15. jsStack
  16. <return self.stack>
  17. !
  18. messageText
  19. ^ messageText
  20. !
  21. messageText: aString
  22. messageText := aString
  23. ! !
  24. !Error methodsFor: 'initialization'!
  25. initialize
  26. self messageText: 'Errorclass: ', (self class name).
  27. ! !
  28. !Error methodsFor: 'signaling'!
  29. resignal
  30. "Resignal the receiver without changing its exception context"
  31. <throw(self)>
  32. !
  33. signal
  34. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  35. !
  36. signal: aString
  37. self messageText: aString.
  38. self signal
  39. ! !
  40. !Error methodsFor: 'testing'!
  41. isSmalltalkError
  42. <return self.smalltalkError === true>
  43. ! !
  44. !Error class methodsFor: 'helios'!
  45. heliosClass
  46. ^ 'exception'
  47. ! !
  48. !Error class methodsFor: 'instance creation'!
  49. signal
  50. ^ self new signal
  51. !
  52. signal: aString
  53. ^ self new
  54. signal: aString
  55. ! !
  56. Error subclass: #JavaScriptException
  57. instanceVariableNames: 'exception'
  58. package: 'Kernel-Exceptions'!
  59. !JavaScriptException commentStamp!
  60. A JavaScriptException is thrown when a non-Smalltalk exception occurs while in the Smalltalk stack.
  61. See `boot.js` `inContext()` and `BlockClosure >> on:do:`!
  62. !JavaScriptException methodsFor: 'accessing'!
  63. context: aMethodContext
  64. "Set the context from the outside.
  65. See boot.js `inContext()` exception handling"
  66. <self.context = aMethodContext>
  67. !
  68. exception
  69. ^ exception
  70. !
  71. exception: anException
  72. exception := anException
  73. !
  74. messageText
  75. <return 'JavaScript exception: ' + self["@exception"].toString()>
  76. ! !
  77. !JavaScriptException class methodsFor: 'instance creation'!
  78. on: anException
  79. ^ self new
  80. exception: anException;
  81. yourself
  82. !
  83. on: anException context: aMethodContext
  84. ^ self new
  85. exception: anException;
  86. context: aMethodContext;
  87. yourself
  88. ! !
  89. Error subclass: #MessageNotUnderstood
  90. instanceVariableNames: 'message receiver'
  91. package: 'Kernel-Exceptions'!
  92. !MessageNotUnderstood commentStamp!
  93. This exception is provided to support `Object>>doesNotUnderstand:`.!
  94. !MessageNotUnderstood methodsFor: 'accessing'!
  95. message
  96. ^ message
  97. !
  98. message: aMessage
  99. message := aMessage
  100. !
  101. messageText
  102. ^ self receiver asString, ' does not understand #', self message selector
  103. !
  104. receiver
  105. ^ receiver
  106. !
  107. receiver: anObject
  108. receiver := anObject
  109. ! !
  110. Error subclass: #NonBooleanReceiver
  111. instanceVariableNames: 'object'
  112. package: 'Kernel-Exceptions'!
  113. !NonBooleanReceiver commentStamp!
  114. NonBooleanReceiver exceptions may be thrown when executing inlined methods such as `#ifTrue:` with a non boolean receiver.!
  115. !NonBooleanReceiver methodsFor: 'accessing'!
  116. object
  117. ^ object
  118. !
  119. object: anObject
  120. object := anObject
  121. ! !