Envy opened on Exceptions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Envy opened on Exceptions

Francesco Raymondi
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
Reply | Threaded
Open this post in threaded view
|

Re: Envy opened on Exceptions

Richard Sargent
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:
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.
Reply | Threaded
Open this post in threaded view
|

Re: Envy opened on Exceptions

Francesco Raymondi
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:
>> 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:
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.
Reply | Threaded
Open this post in threaded view
|

Re: Envy opened on Exceptions

Richard Sargent
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?

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.

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.

Also, as I alluded before, always guard for the most specific exception rather than the most general, except in specific areas. In this example, the most specific exception would have been ZeroDivide.

[1/0]
   on: ZeroDivide
   do: [:signal | self logException: signal. signal return: 42 "or whatever :-) " ].

Note also that these days, #on:do: is preferred over #when:do:.



On Mon, Dec 16, 2013 at 5:23 AM, Francesco Raymondi <[hidden email]> wrote:
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:
>> 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:
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 a topic in the Google Groups "VA Smalltalk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/y2iE1MKSY6c/unsubscribe.
To unsubscribe from this group and all its topics, 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 Sargent
Business Development Manager
503-766-4719
[hidden email]
GemTalk Systems
15220 NW Greenbrier Parkway #240
Beaverton, OR 97006

--
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.