Can you give me an example on how to create new exception and call/use that exception in my program? I try to googling but don't seem to find one. Thanks.
----- Original Message ---- From: Randal L. Schwartz merlyn@stonehenge.com To: Alex Chi alex_chi99@yahoo.com Cc: beginners@lists.squeakfoundation.org Sent: Thursday, October 9, 2008 3:53:44 PM Subject: Re: [Newbies] How to create new exception
"Alex" == Alex Chi alex_chi99@yahoo.com writes:
Alex> As a beginner in smalltalk I have a problem on how to create new Alex> exception class. For example I want to create FileNotFoundError, I have Alex> create a new class FileNotFoundError uner class Error. But then I get Alex> confuse where to write the description or defaultAction of my new Alex> exception?
Looks like both #description and #defaultAction are instance-side methods of the classes under Exception.
So you'd define it as an instance-side method in your FileNotFound error.
You do realize that FileDoesNotExistException already exists? Can you just use that?
"Alex" == Alex Chi alex_chi99@yahoo.com writes:
Alex> Can you give me an example on how to create new exception and call/use Alex> that exception in my program? I try to googling but don't seem to find Alex> one. Thanks.
See if this helps.
http://www.cincomsmalltalk.com/userblogs/cincom/digest?content=2001-files-ex...
It's a bit dated but it might give you the information you need. Even uses #on:do: like the ANSI standard suggests.
On Sun, Oct 12, 2008 at 01:50:05AM -0700, Alex Chi wrote:
Can you give me an example on how to create new exception and call/use that exception in my program? I try to googling but don't seem to find one. Thanks.
Create an exception class:
Exception subclass: #SpontaneousCombustionException instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Heat'.
Then use it:
[SpontaneousCombustionException signal] on: SpontaneousCombustionException do: [:ex | Transcript show: 'Explosion detected'; cr]
beginners@lists.squeakfoundation.org