Kernel-Exceptions.st 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. Object subclass: #ErrorHandler
  58. instanceVariableNames: ''
  59. package: 'Kernel-Exceptions'!
  60. !ErrorHandler methodsFor: 'error handling'!
  61. handleError: anError
  62. anError context ifNotNil: [self logErrorContext: anError context].
  63. self logError: anError
  64. ! !
  65. !ErrorHandler methodsFor: 'private'!
  66. log: aString
  67. console log: aString
  68. !
  69. logContext: aContext
  70. aContext home ifNotNil: [
  71. self logContext: aContext home].
  72. self log: aContext receiver asString, '>>', aContext selector
  73. !
  74. logError: anError
  75. self log: anError messageText
  76. !
  77. logErrorContext: aContext
  78. aContext ifNotNil: [
  79. aContext home ifNotNil: [
  80. self logContext: aContext home]]
  81. ! !
  82. ErrorHandler class instanceVariableNames: 'current'!
  83. !ErrorHandler class methodsFor: 'accessing'!
  84. current
  85. ^current ifNil: [current := self new]
  86. !
  87. setCurrent: anHandler
  88. current := anHandler
  89. ! !
  90. !ErrorHandler class methodsFor: 'initialization'!
  91. initialize
  92. self register
  93. !
  94. register
  95. ErrorHandler setCurrent: self new
  96. ! !