Hi All, As a beginner in smalltalk I have a problem on how to create new exception class. For example I want to create FileNotFoundError, I have create a new class FileNotFoundError uner class Error. But then I get confuse where to write the description or defaultAction of my new exception? Thanks. Regards, Alex Chinoura _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Alex" == Alex Chi <[hidden email]> 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? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by 4l3x
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 <[hidden email]> To: Alex Chi <[hidden email]> Cc: [hidden email] Sent: Thursday, October 9, 2008 3:53:44 PM Subject: Re: [Newbies] How to create new exception >>>>> "Alex" == Alex Chi <[hidden email]> 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? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Alex" == Alex Chi <[hidden email]> 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-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 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by 4l3x
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/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by 4l3x
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 <[hidden email]> 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 <[hidden email]> Subject: Re: [Newbies] How to create new exception To: [hidden email] Message-ID: <20081012162000.GG5308@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 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Alex" == Alex Chi <[hidden email]> writes:
Alex> Thanks a lot for all the information. Alex> 1 more question, after create a new exception class then to use it let's say I have to define something like: Alex> Then use it: Alex> [SpontaneousCombustionException signal] Alex> on: SpontaneousCombustionException Alex> do: [:ex | Transcript show: 'Explosion detected'; cr] No, you write: [some code. that might. explode here: youKnow. andMore stuff. ] on: SpontaneousCombustionException do: [:ex | Transcript show: 'Explosion detected'; cr]. And then if any of the code you call in that first block throws a SpontaneousCombustionException, you get into your second block. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by 4l3x
Thank you all! I already solved my problem. Thanks for your help. regards, alex ----- Original Message ---- From: Alex Chi <[hidden email]> To: [hidden email] 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 <[hidden email]> 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 <[hidden email]> Subject: Re: [Newbies] How to create new exception To: [hidden email] Message-ID: <20081012162000.GG5308@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 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
>>>>> "Alex" == Alex Chi <[hidden email]> writes:
Alex> I already solved my problem. Thanks for your help. For the mailing list, and future googlers, can you post what you ended up with? In general, it's rude to ask a question, then say "nevermind, I found the answer" without sharing the answer. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by 4l3x
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 <[hidden email]> To: [hidden email] 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 <[hidden email]> To: [hidden email] 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 <[hidden email]> 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 <[hidden email]> Subject: Re: [Newbies] How to create new exception To: [hidden email] Message-ID: <20081012162000.GG5308@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 <[hidden email]> <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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Wed, Oct 15, 2008 at 5:22 PM, Alex Chi <[hidden email]> wrote:
Which version of Smalltalk are you using? This doesn't look like Squeak to me. If you want an Exception object, you could just return a new instance: fileNotFound ^ FileDoesNotExistException new. Although this method is pretty pointless. I think you're misunderstanding how Exceptions work; you need to do more reading. I'm not sure if Smalltalk Exceptions are well documented anywhere, but I do know that they work in a similar way to exceptions in other programming languages such as Java or Python, so you could Google or get books from a library that describe these. Briefly, Exceptions are intended for handling situations where something goes wrong. See "FileDoesNotExistException class>>example" for an example. Gulik. -- http://people.squeakfoundation.org/person/mikevdg http://gulik.pbwiki.com/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |