Kernel-Exceptions.st 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. !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. package: 'Kernel-Exceptions'!
  35. !MessageNotUnderstood methodsFor: 'accessing'!
  36. message
  37. ^message
  38. !
  39. message: aMessage
  40. message := aMessage
  41. !
  42. messageText
  43. ^self receiver asString, ' does not understand #', self message selector
  44. !
  45. receiver
  46. ^receiver
  47. !
  48. receiver: anObject
  49. receiver := anObject
  50. ! !
  51. Object subclass: #ErrorHandler
  52. instanceVariableNames: ''
  53. package: '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. log: aString
  61. console log: aString
  62. !
  63. logContext: aContext
  64. aContext home ifNotNil: [
  65. self logContext: aContext home].
  66. self log: aContext receiver asString, '>>', aContext selector
  67. !
  68. logError: anError
  69. self log: anError messageText
  70. !
  71. logErrorContext: aContext
  72. aContext ifNotNil: [
  73. aContext home ifNotNil: [
  74. self logContext: aContext home]]
  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. ! !