2
0

Kernel-Exceptions.st 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Smalltalk current createPackage: 'Kernel-Exceptions' properties: #{}!
  2. Object subclass: #Error
  3. instanceVariableNames: 'messageText'
  4. category: 'Kernel-Exceptions'!
  5. !Error methodsFor: 'accessing'!
  6. messageText
  7. ^messageText
  8. !
  9. messageText: aString
  10. messageText := aString
  11. !
  12. context
  13. <return self.context>
  14. !
  15. jsStack
  16. <return self.stack>
  17. ! !
  18. !Error methodsFor: 'signaling'!
  19. signal
  20. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  21. ! !
  22. !Error methodsFor: 'testing'!
  23. isSmalltalkError
  24. <return self.smalltalkError === true>
  25. ! !
  26. !Error class methodsFor: 'instance creation'!
  27. signal: aString
  28. ^self new
  29. messageText: aString;
  30. signal
  31. ! !
  32. Error subclass: #MessageNotUnderstood
  33. instanceVariableNames: 'message receiver'
  34. category: 'Kernel-Exceptions'!
  35. !MessageNotUnderstood methodsFor: 'accessing'!
  36. message
  37. ^message
  38. !
  39. message: aMessage
  40. message := aMessage
  41. !
  42. receiver
  43. ^receiver
  44. !
  45. receiver: anObject
  46. receiver := anObject
  47. !
  48. messageText
  49. ^self receiver asString, ' does not understand #', self message selector
  50. ! !
  51. Object subclass: #ErrorHandler
  52. instanceVariableNames: ''
  53. category: 'Kernel-Exceptions'!
  54. !ErrorHandler methodsFor: 'error handling'!
  55. handleError: anError
  56. anError context ifNotNil: [self logErrorContext: anError context].
  57. self logError: anError
  58. ! !
  59. !ErrorHandler methodsFor: 'private'!
  60. logContext: aContext
  61. aContext home ifNotNil: [
  62. self logContext: aContext home].
  63. self log: aContext receiver asString, '>>', aContext selector
  64. !
  65. logErrorContext: aContext
  66. aContext ifNotNil: [
  67. aContext home ifNotNil: [
  68. self logContext: aContext home]]
  69. !
  70. logError: anError
  71. self log: anError messageText
  72. !
  73. log: aString
  74. console log: aString
  75. ! !
  76. ErrorHandler class instanceVariableNames: 'current'!
  77. !ErrorHandler class methodsFor: 'accessing'!
  78. current
  79. ^current ifNil: [current := self new]
  80. !
  81. setCurrent: anHandler
  82. current := anHandler
  83. ! !
  84. !ErrorHandler class methodsFor: 'initialization'!
  85. initialize
  86. self register
  87. !
  88. register
  89. ErrorHandler setCurrent: self new
  90. ! !