1
0

Kernel-Exceptions.st 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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: #MessageNotUnderstood
  39. instanceVariableNames: 'message receiver'
  40. package: 'Kernel-Exceptions'!
  41. !MessageNotUnderstood methodsFor: 'accessing'!
  42. message
  43. ^message
  44. !
  45. message: aMessage
  46. message := aMessage
  47. !
  48. messageText
  49. ^self receiver asString, ' does not understand #', self message selector
  50. !
  51. receiver
  52. ^receiver
  53. !
  54. receiver: anObject
  55. receiver := anObject
  56. ! !
  57. Error subclass: #NonBooleanReceiver
  58. instanceVariableNames: 'object'
  59. package: 'Kernel-Exceptions'!
  60. !NonBooleanReceiver methodsFor: 'accessing'!
  61. object
  62. ^ object
  63. !
  64. object: anObject
  65. object := anObject
  66. ! !
  67. Object subclass: #ErrorHandler
  68. instanceVariableNames: ''
  69. package: 'Kernel-Exceptions'!
  70. !ErrorHandler methodsFor: 'error handling'!
  71. handleError: anError
  72. anError context ifNotNil: [self logErrorContext: anError context].
  73. self logError: anError
  74. ! !
  75. !ErrorHandler methodsFor: 'private'!
  76. log: aString
  77. console log: aString
  78. !
  79. logContext: aContext
  80. aContext home ifNotNil: [
  81. self logContext: aContext home].
  82. self log: aContext receiver asString, '>>', aContext selector
  83. !
  84. logError: anError
  85. self log: anError messageText
  86. !
  87. logErrorContext: aContext
  88. aContext ifNotNil: [
  89. aContext home ifNotNil: [
  90. self logContext: aContext home]]
  91. ! !
  92. ErrorHandler class instanceVariableNames: 'current'!
  93. !ErrorHandler class methodsFor: 'accessing'!
  94. current
  95. ^current ifNil: [current := self new]
  96. !
  97. setCurrent: anHandler
  98. current := anHandler
  99. ! !
  100. !ErrorHandler class methodsFor: 'initialization'!
  101. initialize
  102. self register
  103. !
  104. register
  105. ErrorHandler setCurrent: self new
  106. ! !