Hi,
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
[ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
or
self try: [ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
thank you
[code] on: Exception do: [:ex | more code]
On 11/24/05, Damien Cassou damien.cassou@laposte.net wrote:
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
On 24-Nov-05, at 12:50 PM, Damien Cassou wrote:
Cees De Groot a écrit :
[code] on: Exception do: [:ex | more code]
*really* important point; look up the classes inheriting from Exception - use the hierarchybrowser is my advice - and learn about using the correct form of exception to suit your code. Trapping the generic Exception is likely to cause much pain.
Some reasonable examples of using a more specific exception can be found if you look for all reference to the class ZeroDivide (which is for divide by 0 exceptions, surprise) or FileDoesNotExistException.
tim
*really* important point; look up the classes inheriting from Exception - use the hierarchybrowser is my advice - and learn about using the correct form of exception to suit your code. Trapping the generic Exception is likely to cause much pain.
Some reasonable examples of using a more specific exception can be found if you look for all reference to the class ZeroDivide (which is for divide by 0 exceptions, surprise) or FileDoesNotExistException.
I've already read the thread "self error considered harmfull". I'll try to remember, thank you
Bye
Damien
read the ExceptionTest classes they are gorgeous. Really This is the best documentation on exception catching I ever read... :)
Stef
On 24 nov. 05, at 20:49, Damien Cassou wrote:
Hi,
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
[ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
or
self try: [ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
thank you
-- Damien
I may be overstepping my bounds here as an almost complete Squeak newb, but given you mentioned "try/catch" then you're probably thinking "in Java" so you'll want to know about finally - which as far as I can tell is done by:
[code] on: Exception do: [:ex | more code] ensure: [do this no matter what]
(ie the ensure: [] is the same as a finally).
Just my $0.02 - if I'm wrong somebody please correct me :)
stéphane ducasse wrote:
Damien
read the ExceptionTest classes they are gorgeous. Really This is the best documentation on exception catching I ever read... :)
Stef
On 24 nov. 05, at 20:49, Damien Cassou wrote:
Hi,
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
[ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
or
self try: [ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
thank you
-- Damien
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
Simon,
Le 25 nov. 05, à 11:12, Simon Kirk a écrit :
I may be overstepping my bounds here as an almost complete Squeak newb, but given you mentioned "try/catch" then you're probably thinking "in Java" so you'll want to know about finally - which as far as I can tell is done by:
[code] on: Exception do: [:ex | more code] ensure: [do this no matter what]
(ie the ensure: [] is the same as a finally).
There is no #on:do:ensure: method. One have to send 2 messages : #ensure: and #on:do:
[[code] ensure: [do this no matter what]] on: Exception do: [:ex| more code]
Note : the "ensure block" is performed after the exception handling (do block)
Noury
Just my $0.02 - if I'm wrong somebody please correct me :)
stéphane ducasse wrote:
Damien
read the ExceptionTest classes they are gorgeous. Really This is the best documentation on exception catching I ever read... :)
Stef
On 24 nov. 05, at 20:49, Damien Cassou wrote:
Hi,
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
[ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
or
self try: [ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
thank you
-- Damien
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
-------------------------------------------------------------- Dr. Noury Bouraqadi - Enseignant/Chercheur Ecole des Mines de Douai - Dept. G.I.P http://csl.ensm-douai.fr/noury
European Smalltalk Users Group Board http://www.esug.org
Squeak: an Open Source Smalltalk http://www.squeak.org --------------------------------------------------------------
Ah thanks Noury - I admit that I was confused about the order in which the calls should be made, now it makes more object-sense :)
Noury Bouraqadi wrote:
Simon,
Le 25 nov. 05, à 11:12, Simon Kirk a écrit :
I may be overstepping my bounds here as an almost complete Squeak newb, but given you mentioned "try/catch" then you're probably thinking "in Java" so you'll want to know about finally - which as far as I can tell is done by:
[code] on: Exception do: [:ex | more code] ensure: [do this no matter what]
(ie the ensure: [] is the same as a finally).
There is no #on:do:ensure: method. One have to send 2 messages : #ensure: and #on:do:
[[code] ensure: [do this no matter what]] on: Exception do: [:ex| more code]
Note : the "ensure block" is performed after the exception handling (do block)
Noury
Just my $0.02 - if I'm wrong somebody please correct me :)
stéphane ducasse wrote:
Damien
read the ExceptionTest classes they are gorgeous. Really This is the best documentation on exception catching I ever read... :)
Stef
On 24 nov. 05, at 20:49, Damien Cassou wrote:
Hi,
How can I try/catch for errors in Squeak ? I didn't find anything. I would like to do something like :
[ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
or
self try: [ aPieceOfCodeThatCanThrowsExceptions ] catch: [:exception | Transcript show: exception]
thank you
-- Damien
This message has been scanned for viruses by BlackSpider MailControl
- www.blackspider.com
Dr. Noury Bouraqadi - Enseignant/Chercheur Ecole des Mines de Douai - Dept. G.I.P http://csl.ensm-douai.fr/noury
European Smalltalk Users Group Board http://www.esug.org
Squeak: an Open Source Smalltalk http://www.squeak.org
squeak-dev@lists.squeakfoundation.org