1

I know how to raise an exception and how to handle it , but suppose I have this method:

method1:arg
AssertionFailure signal:'rescue error comment'.

I want to catch this exception and create new Assertion failure exception with another format.However I need to get that message ("rescue error comment") and use it in my new exception.. and this is where I don't know what to do...

so how do I get that message before the handling the exeption by using

   on: AssertionFailure  do:
Ohad
  • 1,563
  • 2
  • 20
  • 44
  • I don't really understand your question. You have an error, and you can catch it with `#on:do:` why do you want to change it somewhere in a middle? Why don't you signal something different then _AssertionFailure_? Why don't you signal exactly what you want? – Uko Dec 12 '14 at 07:29
  • ya it might seem a bit weird.. but my new Assertion failure has a different format.. and I just need to find a way to save that signal message.. is there any way ? – Ohad Dec 12 '14 at 07:40
  • 1
    Either you do `on: AssertionFailure do: [ :e | NewAssertionFailure signal: e messageText ]` or you do `NewAssertionFailure signal: e messageText` directly in `method1:arg`. If you can tell why these 2 options are bad, maybe I'll be able to figure out which solution would be good. – Uko Dec 12 '14 at 08:47
  • no this is perfect.. I have used on: AssertionFailure do: [ :e | NewAssertionFailure signal: e messageText ] and it works.. this is what I wanted :-) you are the best – Ohad Dec 12 '14 at 10:11
  • You are welcome, mover solution to answer – Uko Dec 12 '14 at 10:27

1 Answers1

1

Either use

on: AssertionFailure do: [ :e | NewAssertionFailure signal: e messageText ]

or define method as

method1:arg
    NewAssertionFailure signal: 'rescue error comment'
Uko
  • 13,134
  • 6
  • 58
  • 106