Kernel-Exceptions.st 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. Smalltalk current createPackage: 'Kernel-Exceptions' properties: #{}!
  2. Object subclass: #Error
  3. instanceVariableNames: 'messageText'
  4. package: 'Kernel-Exceptions'!
  5. !Error methodsFor: 'accessing'!
  6. context
  7. <return self.context>
  8. !
  9. jsStack
  10. <return self.stack>
  11. !
  12. messageText
  13. ^messageText
  14. !
  15. messageText: aString
  16. messageText := aString
  17. ! !
  18. !Error methodsFor: 'signaling'!
  19. signal
  20. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  21. !
  22. signal: aString
  23. self messageText: aString.
  24. self signal
  25. ! !
  26. !Error methodsFor: 'testing'!
  27. isSmalltalkError
  28. <return self.smalltalkError === true>
  29. ! !
  30. !Error class methodsFor: 'instance creation'!
  31. signal
  32. ^self new signal
  33. !
  34. signal: aString
  35. ^self new
  36. signal: aString
  37. ! !
  38. Error subclass: #Continuation
  39. instanceVariableNames: 'context'
  40. package: 'Kernel-Exceptions'!
  41. !Continuation methodsFor: 'initialization'!
  42. initializeFromContext: aContext
  43. "Add a cc flag to the error object so Smalltalk knows how to handle it"
  44. super initialize.
  45. context := aContext.
  46. self basicAt: 'cc' put: true
  47. !
  48. restore
  49. context resume
  50. !
  51. value: aBlock
  52. aBlock value: self.
  53. self signal
  54. ! !
  55. !Continuation class methodsFor: 'instance creation'!
  56. currentDo: aBlock
  57. ^ self new
  58. initializeWithContext: thisContext home;
  59. value: aBlock
  60. ! !
  61. Error subclass: #MessageNotUnderstood
  62. instanceVariableNames: 'message receiver'
  63. package: 'Kernel-Exceptions'!
  64. !MessageNotUnderstood methodsFor: 'accessing'!
  65. message
  66. ^message
  67. !
  68. message: aMessage
  69. message := aMessage
  70. !
  71. messageText
  72. ^self receiver asString, ' does not understand #', self message selector
  73. !
  74. receiver
  75. ^receiver
  76. !
  77. receiver: anObject
  78. receiver := anObject
  79. ! !
  80. Object subclass: #ErrorHandler
  81. instanceVariableNames: ''
  82. package: 'Kernel-Exceptions'!
  83. !ErrorHandler methodsFor: 'error handling'!
  84. handleError: anError
  85. anError context ifNotNil: [self logErrorContext: anError context].
  86. self logError: anError
  87. ! !
  88. !ErrorHandler methodsFor: 'private'!
  89. log: aString
  90. console log: aString
  91. !
  92. logContext: aContext
  93. aContext home ifNotNil: [
  94. self logContext: aContext home].
  95. self log: aContext receiver asString, '>>', aContext selector
  96. !
  97. logError: anError
  98. self log: anError messageText
  99. !
  100. logErrorContext: aContext
  101. aContext ifNotNil: [
  102. aContext home ifNotNil: [
  103. self logContext: aContext home]]
  104. ! !
  105. ErrorHandler class instanceVariableNames: 'current'!
  106. !ErrorHandler class methodsFor: 'accessing'!
  107. current
  108. ^current ifNil: [current := self new]
  109. !
  110. setCurrent: anHandler
  111. current := anHandler
  112. ! !
  113. !ErrorHandler class methodsFor: 'initialization'!
  114. initialize
  115. self register
  116. !
  117. register
  118. ErrorHandler setCurrent: self new
  119. ! !