[Newbies] How to create new exception
Alex Chi
alex_chi99 at yahoo.com
Wed Oct 15 04:22:41 UTC 2008
Sorry for the that, I mean my problem is I put the exception in the wrong part of my program, so everytime I try to call it in the method it does not return the exception, so what i did was:
1. Create an new exception class, which is: FileNotFoundError
Smalltalk.Core defineClass: #FileNotFound
superclass: #{Core.Error}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: ''
2. I use that new exception to raise signal on a FileNotFoundError.
fileNotFound
^FileNotFound raiseSignal: 'The file is not exist'
At first I'm using handler on:[...] do: [..] but I only need to define my own description of FileNotFoundError so that's all I need to do.
I'm still a beginner so sometimes I misunderstood and get confused.
Really appreciate all your help.
----- Original Message ----
From: Alex Chi <alex_chi99 at yahoo.com>
To: beginners at lists.squeakfoundation.org
Sent: Monday, October 13, 2008 5:18:43 PM
Subject: Re: [Newbies] How to create new exception
Thank you all!
I already solved my problem. Thanks for your help.
regards,
alex
----- Original Message ----
From: Alex Chi <alex_chi99 at yahoo.com>
To: beginners at lists.squeakfoundation.org
Sent: Monday, October 13, 2008 12:31:18 PM
Subject: Re: [Newbies] How to create new exception
Thanks a lot for all the information.
1 more question, after create a new exception class then to use it let's say I have to define something like:
Then use it:
[SpontaneousCombustionException signal]
on: SpontaneousCombustionException
do: [:ex | Transcript show: 'Explosion detected'; cr]
My question is where do I write this code? Is it in one of my method for example I create spontaneousCombustionSignal method, and I write this code there?
>>>>> "Alex" == Alex Chi <alex_chi99 at 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.
------------------------------
Message: 4
Date: Sun, 12 Oct 2008 09:20:00 -0700
From: Matthew Fulmer <tapplek at gmail.com>
Subject: Re: [Newbies] How to create new exception
To: beginners at lists.squeakfoundation.org
Message-ID: <20081012162000.GG5308 at tacobell>
Content-Type: text/plain; charset=us-ascii
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]
--
Matthew Fulmer -- http://mtfulmer.wordpress.com/
See if this helps.
http://www.cincomsmalltalk.com/userblogs/cincom/digest?content=2001-files-exceptions
It's a bit dated but it might give you the information you need.
Even uses #on:do: like the ANSI standard suggests.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20081014/7bae7146/attachment.htm
More information about the Beginners
mailing list