Hi all,
-- I have a problem with exceptions: when I want to handle an exception like in the example below: [1/0 ] when: ExAll do: [:signal | Transcript show: 'Error' ] the Transcript shows the string 'Error' correctly, but the ENVY also opens (I attached a picture with ENVY) Why? What I mistake? My configuration is: VA ST 6.0.2 WidgetKit 6.0.2 WindowBuilder Pro 6.0.2 Thank you very much. Regards, Francesco You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. 2013_12_13_17_08_58_ENVY_Smalltalk_Debugger_on_13_12_2013_17_06_08_.png (59K) Download Attachment |
Administrator
|
>> the Transcript shows the string 'Error' correctly, but the *debugger* also opens
-- The problem is that you have not specified what to do with the exception. The default is to resume. Look at the "ANSI-API (signaledException)" category of Signal. You may want to use #return or #return: to provide a replacement value for the outcome of the failed block. By the way, catching all exception is a potential weakness in a program, unless it is in the outermost part of execution (e.g., in a read and dispatch loop). Even then, it means your handler will be responding to Warnings and Notifications, not just Errors. You almost certainly will want to respond differently to resumable exceptions versus non-resumable ones. On Friday, December 13, 2013 8:17:53 AM UTC-8, Francesco Raymondi wrote:
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Richard, I tried to do your solution but I'm not sure to have understood ...
-- Instead, I wrote something like this and it works: [1/0] when: ExAll do: [:signal| Transcript show: (signal argument) . signal exitWith: [error]]. I have no idea if this solution will generate some problems or not. Thank you for help. Regards Il giorno venerdì 13 dicembre 2013 18:45:52 UTC+1, Richard Sargent ha scritto:
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Administrator
|
That is basically correct. The argument to #exitWith: (ANSI: #return:) should be consistent with what the guarded block should have returned. In your case, you have returned a Block evaluating some kind of variable named "error". Is that really what you wanted? Assuming the example you provided was in a method called #determineSomething, my preferred approach is to create a #determineSomethingOr: method which takes a Block for an argument. In the example you provided, you wouldn't tell the signal to exit, you would instead answer the value of the Block argument (e.g. ^aBlock value). This unwinds the stack, dropping the exception, etc.For example, the code that would have called 1/0 was expecting a number back, so typically the exception handler should return a number e.g. 0. Alternatively, but poorer, is to return nil or some other special value ... but that is a Java-like approach, so there are better ways along the lines of the #at:ifAbsent: methods. [1/0] On Mon, Dec 16, 2013 at 5:23 AM, Francesco Raymondi <[hidden email]> wrote:
--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at http://groups.google.com/group/va-smalltalk. For more options, visit https://groups.google.com/groups/opt_out. |
Free forum by Nabble | Edit this page |