Kernel-Exceptions.st 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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: 'initialization'!
  19. initialize
  20. self messageText: 'Errorclass: ', (self class name).
  21. ! !
  22. !Error methodsFor: 'signaling'!
  23. signal
  24. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  25. !
  26. signal: aString
  27. self messageText: aString.
  28. self signal
  29. ! !
  30. !Error methodsFor: 'testing'!
  31. isSmalltalkError
  32. <return self.smalltalkError === true>
  33. ! !
  34. !Error class methodsFor: 'instance creation'!
  35. signal
  36. ^self new signal
  37. !
  38. signal: aString
  39. ^self new
  40. signal: aString
  41. ! !
  42. Error subclass: #MessageNotUnderstood
  43. instanceVariableNames: 'message receiver'
  44. package: 'Kernel-Exceptions'!
  45. !MessageNotUnderstood methodsFor: 'accessing'!
  46. message
  47. ^message
  48. !
  49. message: aMessage
  50. message := aMessage
  51. !
  52. messageText
  53. ^self receiver asString, ' does not understand #', self message selector
  54. !
  55. receiver
  56. ^receiver
  57. !
  58. receiver: anObject
  59. receiver := anObject
  60. ! !
  61. Error subclass: #NonBooleanReceiver
  62. instanceVariableNames: 'object'
  63. package: 'Kernel-Exceptions'!
  64. !NonBooleanReceiver methodsFor: 'accessing'!
  65. object
  66. ^ object
  67. !
  68. object: anObject
  69. object := anObject
  70. ! !
  71. Object subclass: #ErrorHandler
  72. instanceVariableNames: ''
  73. package: 'Kernel-Exceptions'!
  74. !ErrorHandler methodsFor: 'error handling'!
  75. handleError: anError
  76. anError context ifNotNil: [self logErrorContext: anError context].
  77. self logError: anError
  78. ! !
  79. !ErrorHandler methodsFor: 'private'!
  80. log: aString
  81. console log: aString
  82. !
  83. logContext: aContext
  84. aContext home ifNotNil: [
  85. self logContext: aContext home].
  86. self log: aContext receiver asString, '>>', aContext selector asString
  87. !
  88. logError: anError
  89. self log: anError messageText
  90. !
  91. logErrorContext: aContext
  92. aContext ifNotNil: [
  93. aContext home ifNotNil: [
  94. self logContext: aContext home]]
  95. ! !
  96. ErrorHandler class instanceVariableNames: 'current'!
  97. !ErrorHandler class methodsFor: 'accessing'!
  98. current
  99. ^current ifNil: [current := self new]
  100. !
  101. setCurrent: anHandler
  102. current := anHandler
  103. ! !
  104. !ErrorHandler class methodsFor: 'initialization'!
  105. initialize
  106. self register
  107. !
  108. register
  109. ErrorHandler setCurrent: self new
  110. ! !