Hi All,
I have this idea that I would like to discuss on the next Pharo sprint and maybe start to implement if there is some consensus on it. It has been mentioned many times before on this list that Object>>#error: should be replaced by signalling specific Exceptions in as many cases as possible (or where it makes sense). Even today, there was http://code.google.com/p/pharo/issues/detail?id=3987 ! I think the core system should set the example here, by defining a number of general purpose exceptions and by using them. Going over #error: senders will be a lot of work but can be done in incremental/Pharo steps. So I went over the current hierarchy, scanned quickly through their references and some #error: senders by fundamental classes and looked at some other Smalltalks. I came up with the following very rough draft of an extended hierarchy (** marks new exceptions). In between brackets are the instance variables. Of course, we have to discuss about naming, instance variables and opportunities for reuse and inheritance (could be fun). I am no expert on exceptions and would certainly like to learn more. I am probably overlooking some aspects. We have to keep this Smalltalk like, flexible, dynamic, not start mimicing other languages. Any step in this direction will be an improvement over the current situation. Really using them correctly throughout the system will take some time. Defining the hierarchy could be done rather quickly. Refactoring is always possible later on. Exception (messageText) Abort Error ArithemticError ZeroDivide (dividend) FloatingPointException RangeError ** (from, to) NaNError ** FileStreamException (fileName) FileDoesNotExistException (readOnly) FileExistsException (fileClass) CannotDeleteFileException FileWriteError FileReadError ** FileClosedException ** CannotAccessFileException ** ReadonlyFileException ** MessageNotUnderstood (message, receiver) NonBooleanReceiver (object) OutOfMemory Halt AssertionFailure BreakPoint SyntaxError ** !exists! (input, position) NumberFormatException ** HeadlessError ** TimedOut ** (object, operation, timeout) VerificationException IllegalOperation ** (operation, object) SizeMismatch (objects) LowMemory ** (percentageFree) SubclassResponsibility ** (message, receiver) NotYetImplemented ** (message, receiver) CannotInstanciate ** (class) ReadOnlyObject ** (object) OutOfFreeSpace ** (object, size) InvalidArgument ** (message, receiver, argument) NotIndexable ** (object) NoKeyedAccess ** (object) NonIntegerIndex ** (receiver, index) SubscriptOutOfBounds ** (receiver, index, from, to) NotFoundException ** (receiver, object) KeyNotFound ** ValueNotFound ** ElementNotFound ** StreamException (stream) PositionError ** (index, from, to) EndOfStream ** BeginOfStream ** All feedback is welcome. Regards, Sven |
Hi Sven,
+1 The exception hierarchy needs some work, indeed. If you make all your new exception a subclass of Error, you should not have a problem with the existing handler I imagine. Alexandre On 11 Apr 2011, at 10:10, Sven Van Caekenberghe wrote: > Hi All, > > I have this idea that I would like to discuss on the next Pharo sprint and maybe start to implement if there is some consensus on it. > > It has been mentioned many times before on this list that Object>>#error: should be replaced by signalling specific Exceptions in as many cases as possible (or where it makes sense). Even today, there was http://code.google.com/p/pharo/issues/detail?id=3987 ! > > I think the core system should set the example here, by defining a number of general purpose exceptions and by using them. Going over #error: senders will be a lot of work but can be done in incremental/Pharo steps. > > So I went over the current hierarchy, scanned quickly through their references and some #error: senders by fundamental classes and looked at some other Smalltalks. I came up with the following very rough draft of an extended hierarchy (** marks new exceptions). In between brackets are the instance variables. Of course, we have to discuss about naming, instance variables and opportunities for reuse and inheritance (could be fun). > > I am no expert on exceptions and would certainly like to learn more. I am probably overlooking some aspects. We have to keep this Smalltalk like, flexible, dynamic, not start mimicing other languages. > > Any step in this direction will be an improvement over the current situation. Really using them correctly throughout the system will take some time. Defining the hierarchy could be done rather quickly. Refactoring is always possible later on. > > Exception (messageText) > Abort > Error > ArithemticError > ZeroDivide (dividend) > FloatingPointException > RangeError ** (from, to) > NaNError ** > FileStreamException (fileName) > FileDoesNotExistException (readOnly) > FileExistsException (fileClass) > CannotDeleteFileException > FileWriteError > FileReadError ** > FileClosedException ** > CannotAccessFileException ** > ReadonlyFileException ** > MessageNotUnderstood (message, receiver) > NonBooleanReceiver (object) > OutOfMemory > Halt > AssertionFailure > BreakPoint > SyntaxError ** !exists! (input, position) > NumberFormatException ** > HeadlessError ** > TimedOut ** (object, operation, timeout) > VerificationException > IllegalOperation ** (operation, object) > SizeMismatch (objects) > LowMemory ** (percentageFree) > SubclassResponsibility ** (message, receiver) > NotYetImplemented ** (message, receiver) > CannotInstanciate ** (class) > ReadOnlyObject ** (object) > OutOfFreeSpace ** (object, size) > InvalidArgument ** (message, receiver, argument) > NotIndexable ** (object) > NoKeyedAccess ** (object) > NonIntegerIndex ** (receiver, index) > SubscriptOutOfBounds ** (receiver, index, from, to) > NotFoundException ** (receiver, object) > KeyNotFound ** > ValueNotFound ** > ElementNotFound ** > StreamException (stream) > PositionError ** (index, from, to) > EndOfStream ** > BeginOfStream ** > > All feedback is welcome. > > Regards, > > Sven > > > -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. |
In reply to this post by Sven Van Caekenberghe
this is a good idea.
Now pay attention that we should restart to work on integrating FS and that the file exception may change. Stef On Apr 11, 2011, at 4:10 PM, Sven Van Caekenberghe wrote: > Hi All, > > I have this idea that I would like to discuss on the next Pharo sprint and maybe start to implement if there is some consensus on it. > > It has been mentioned many times before on this list that Object>>#error: should be replaced by signalling specific Exceptions in as many cases as possible (or where it makes sense). Even today, there was http://code.google.com/p/pharo/issues/detail?id=3987 ! > > I think the core system should set the example here, by defining a number of general purpose exceptions and by using them. Going over #error: senders will be a lot of work but can be done in incremental/Pharo steps. > > So I went over the current hierarchy, scanned quickly through their references and some #error: senders by fundamental classes and looked at some other Smalltalks. I came up with the following very rough draft of an extended hierarchy (** marks new exceptions). In between brackets are the instance variables. Of course, we have to discuss about naming, instance variables and opportunities for reuse and inheritance (could be fun). > > I am no expert on exceptions and would certainly like to learn more. I am probably overlooking some aspects. We have to keep this Smalltalk like, flexible, dynamic, not start mimicing other languages. > > Any step in this direction will be an improvement over the current situation. Really using them correctly throughout the system will take some time. Defining the hierarchy could be done rather quickly. Refactoring is always possible later on. > > Exception (messageText) > Abort > Error > ArithemticError > ZeroDivide (dividend) > FloatingPointException > RangeError ** (from, to) > NaNError ** > FileStreamException (fileName) > FileDoesNotExistException (readOnly) > FileExistsException (fileClass) > CannotDeleteFileException > FileWriteError > FileReadError ** > FileClosedException ** > CannotAccessFileException ** > ReadonlyFileException ** > MessageNotUnderstood (message, receiver) > NonBooleanReceiver (object) > OutOfMemory > Halt > AssertionFailure > BreakPoint > SyntaxError ** !exists! (input, position) > NumberFormatException ** > HeadlessError ** > TimedOut ** (object, operation, timeout) > VerificationException > IllegalOperation ** (operation, object) > SizeMismatch (objects) > LowMemory ** (percentageFree) > SubclassResponsibility ** (message, receiver) > NotYetImplemented ** (message, receiver) > CannotInstanciate ** (class) > ReadOnlyObject ** (object) > OutOfFreeSpace ** (object, size) > InvalidArgument ** (message, receiver, argument) > NotIndexable ** (object) > NoKeyedAccess ** (object) > NonIntegerIndex ** (receiver, index) > SubscriptOutOfBounds ** (receiver, index, from, to) > NotFoundException ** (receiver, object) > KeyNotFound ** > ValueNotFound ** > ElementNotFound ** > StreamException (stream) > PositionError ** (index, from, to) > EndOfStream ** > BeginOfStream ** > > All feedback is welcome. > > Regards, > > Sven > > > |
In reply to this post by Sven Van Caekenberghe
sven did you get a look at issue 3999 since camillo started.
http://code.google.com/p/pharo/issues/detail?id=3999 Stef On Apr 11, 2011, at 4:10 PM, Sven Van Caekenberghe wrote: > Hi All, > > I have this idea that I would like to discuss on the next Pharo sprint and maybe start to implement if there is some consensus on it. > > It has been mentioned many times before on this list that Object>>#error: should be replaced by signalling specific Exceptions in as many cases as possible (or where it makes sense). Even today, there was http://code.google.com/p/pharo/issues/detail?id=3987 ! > > I think the core system should set the example here, by defining a number of general purpose exceptions and by using them. Going over #error: senders will be a lot of work but can be done in incremental/Pharo steps. > > So I went over the current hierarchy, scanned quickly through their references and some #error: senders by fundamental classes and looked at some other Smalltalks. I came up with the following very rough draft of an extended hierarchy (** marks new exceptions). In between brackets are the instance variables. Of course, we have to discuss about naming, instance variables and opportunities for reuse and inheritance (could be fun). > > I am no expert on exceptions and would certainly like to learn more. I am probably overlooking some aspects. We have to keep this Smalltalk like, flexible, dynamic, not start mimicing other languages. > > Any step in this direction will be an improvement over the current situation. Really using them correctly throughout the system will take some time. Defining the hierarchy could be done rather quickly. Refactoring is always possible later on. > > Exception (messageText) > Abort > Error > ArithemticError > ZeroDivide (dividend) > FloatingPointException > RangeError ** (from, to) > NaNError ** > FileStreamException (fileName) > FileDoesNotExistException (readOnly) > FileExistsException (fileClass) > CannotDeleteFileException > FileWriteError > FileReadError ** > FileClosedException ** > CannotAccessFileException ** > ReadonlyFileException ** > MessageNotUnderstood (message, receiver) > NonBooleanReceiver (object) > OutOfMemory > Halt > AssertionFailure > BreakPoint > SyntaxError ** !exists! (input, position) > NumberFormatException ** > HeadlessError ** > TimedOut ** (object, operation, timeout) > VerificationException > IllegalOperation ** (operation, object) > SizeMismatch (objects) > LowMemory ** (percentageFree) > SubclassResponsibility ** (message, receiver) > NotYetImplemented ** (message, receiver) > CannotInstanciate ** (class) > ReadOnlyObject ** (object) > OutOfFreeSpace ** (object, size) > InvalidArgument ** (message, receiver, argument) > NotIndexable ** (object) > NoKeyedAccess ** (object) > NonIntegerIndex ** (receiver, index) > SubscriptOutOfBounds ** (receiver, index, from, to) > NotFoundException ** (receiver, object) > KeyNotFound ** > ValueNotFound ** > ElementNotFound ** > StreamException (stream) > PositionError ** (index, from, to) > EndOfStream ** > BeginOfStream ** > > All feedback is welcome. > > Regards, > > Sven > > > |
I like the idea. Another thing that we may think about is the exception conventio name...
Do the classes need a suffix or not ? which ones? Exception/Error/Warning? when Exception and when Error ? Cheers Mariano On Wed, Apr 13, 2011 at 9:24 AM, Stéphane Ducasse <[hidden email]> wrote: sven did you get a look at issue 3999 since camillo started. -- Mariano http://marianopeck.wordpress.com |
In reply to this post by Sven Van Caekenberghe
On Mon, Apr 11, 2011 at 4:10 PM, Sven Van Caekenberghe <[hidden email]> wrote: Hi All, You probably know the PharoByExample chapter on exceptions, but just in case: https://gforge.inria.fr/frs/download.php/26600/PBE2-Exceptions-2010-03-02.pdf Cheers Mariano I am probably overlooking some aspects. We have to keep this Smalltalk like, flexible, dynamic, not start mimicing other languages. -- Mariano http://marianopeck.wordpress.com |
On 13 Apr 2011, at 10:50, Mariano Martinez Peck wrote: > You probably know the PharoByExample chapter on exceptions, > but just in case: https://gforge.inria.fr/frs/download.php/26600/PBE2-Exceptions-2010-03-02.pdf Seems like the right kind of preparation, I will reread it. I love written documentation. Thanks! Sven |
Hey,
What I've seen so far and I like is to use small helper methods to signal exceptions: "usage" Dictionary >> at: aKey ... self keyNotFound: aKey. "helper method to fill the exceptions params" Dictionary >> keyNotFound: aKey KeyNotFoundException signalWithKey: aKey "helper to signal an Exception" KeyNotFoundException class >> signalWithKey: aKey self new key: aKey; signal. At least one of the helper methods should be present to make the code more readable, I think. And as Mariano pointed out, there should be a convention on the naming: I am still not sure about suffixing the exception classes with "Exception", but I guess this is a good thing to do. Though I must say that I omitted it so far ;) and just put the verb there, but that can be easily changed. The exception hierarchy looks nice ;), I think in this matter we can learn a bit from Java. And I would certainly like to see these error messages infect the whole system ;). camillo On 2011-04-13, at 11:03, Sven Van Caekenberghe wrote:
|
In reply to this post by Sven Van Caekenberghe
> You probably know the PharoByExample chapter on exceptions,
>> but just in case: https://gforge.inria.fr/frs/download.php/26600/PBE2-Exceptions-2010-03-02.pdf > > Seems like the right kind of preparation, I will reread it. > I love written documentation. me too :) this is why I write it and I would love to have a chapter on Zinc for the new book :). > Thanks! > > Sven > > > |
In reply to this post by Camillo Bruni
El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió:
> And as Mariano pointed out, there should be a convention on the > naming: I am still not sure about suffixing the exception classes with > "Exception", but I guess this is a good thing to do. Though I must say > that I omitted it so far ;) and just put the verb there, but that can > be easily changed. I would say no to suffixes. Analogous to announcements, they shouldn't have the suffix. The name should be descriptive enough and intention revealing that the suffix isn't needed in most cases. For example, I think that DividedByZero is better than DividedByZeroException and no information is lost with the sorter name. Instead, DivideByZero isn't clear enough to indicate that is a event that happened. What do you think? -- Miguel Cobá http://twitter.com/MiguelCobaMtz http://miguel.leugim.com.mx |
On 2011-04-13, at 18:55, Miguel Cobá wrote:
If this has been applied in the same sense before and its not a big deal I would prefer no suffixes as well. camillo |
In reply to this post by Miguel Cobá
I think it is not a good idea to use the prefix Exception. We do not use the word "exception" in real life, so we should not do it on our systems.
About the proposed hierarchy, the problem with having specific exceptions is that they are important for those who catch them, not for those who signal them. For example, besides the name, what is the difference between KeyNotFound or ValueNotFound? none. So, I think that the exception hierarchy should be grown from it uses, not created based on how or where they are signaled.
my 2 cents :-)
On Wed, Apr 13, 2011 at 1:55 PM, Miguel Cobá <[hidden email]> wrote: El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: -- Hernán Wilkinson
Agile Software Development, Teaching & Coaching Mobile: +54 - 911 - 4470 - 7207 email: [hidden email] site: http://www.10Pines.com |
Some thoughts from an old man (started programming before exceptions of
any kind were available:) ... In the old days, error numbers had a place in the universe ... error numbers of a certain range indicated specific errors and the "error handlers" could check for a range or a specific error ... Today I think there is still a place for the notion of "error numbers". In Smalltalk I would use Symbols instead of numbers, but the idea would be to use a concrete exception class to identify broad categories of error conditions (i.e., FileStreamError) and a symbolic "reason code" to indicate the specific error (i.e., #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an error handler can be written for FileStreamError and then specific action take with respect to which "reason code" is involved, if such action is needed. The main advantage of using reasonCodes over using a "class per error condition" is that you can reduce the size of the Exception hierarchy to a manageable size (GemStone has hundreds of error conditions, so we've resorted to using "reason codes" to manage the size of the hierarchy). As Hernan hints, more often than not it is important to be very specific about the error condition when signalling an error (a unique error message per "per reason code" would be desirable), but the there are very few places where the handler is going to be that specific ... In other words, if it is likely that programmers in the course of using an application will be writing specific error handlers to distinguish between the KeyNotFound and ValueNotFound condition, then classes should be created, otherwise, the NotFoundException could be implemented with three reason codes: #keyNotFound, #valueNotFound, and #elementNotFound and you'd get the best of both worlds, explicit information at the signalling site and a much smaller and more manageable Exception class hierarchy. Dale On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: > I think it is not a good idea to use the prefix Exception. We do not use > the word "exception" in real life, so we should not do it on our systems. > About the proposed hierarchy, the problem with having specific > exceptions is that they are important for those who catch them, not for > those who signal them. For example, besides the name, what is the > difference between KeyNotFound or ValueNotFound? none. So, I think that > the exception hierarchy should be grown from it uses, not created based > on how or where they are signaled. > > my 2 cents :-) > > On Wed, Apr 13, 2011 at 1:55 PM, Miguel Cobá <[hidden email] > <mailto:[hidden email]>> wrote: > > El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: > > > And as Mariano pointed out, there should be a convention on the > > naming: I am still not sure about suffixing the exception classes > with > > "Exception", but I guess this is a good thing to do. Though I > must say > > that I omitted it so far ;) and just put the verb there, but that can > > be easily changed. > > I would say no to suffixes. Analogous to announcements, they shouldn't > have the suffix. The name should be descriptive enough and intention > revealing that the suffix isn't needed in most cases. For example, I > think that > > DividedByZero > > is better than > > DividedByZeroException > > and no information is lost with the sorter name. Instead, DivideByZero > isn't clear enough to indicate that is a event that happened. > > What do you think? > > -- > Miguel Cobá > http://twitter.com/MiguelCobaMtz > http://miguel.leugim.com.mx > > > > > > > > -- > *Hernán Wilkinson > Agile Software Development, Teaching & Coaching > Mobile: +54 - 911 - 4470 - 7207 > email: [hidden email] > site: http://www.10Pines.com <http://www.10pines.com/>* > |
Thanks a lot everybody for the reactions, this could become a nice discussion next Friday.
All points raised are valid, I would like simple names and a compact multipurpose hierarchy too. On 13 Apr 2011, at 19:39, Dale Henrichs wrote: > Some thoughts from an old man (started programming before exceptions of any kind were available:) ... > > In the old days, error numbers had a place in the universe ... error numbers of a certain range indicated specific errors and the "error handlers" could check for a range or a specific error ... > > Today I think there is still a place for the notion of "error numbers". > > In Smalltalk I would use Symbols instead of numbers, but the idea would be to use a concrete exception class to identify broad categories of error conditions (i.e., FileStreamError) and a symbolic "reason code" to indicate the specific error (i.e., #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an error handler can be written for FileStreamError and then specific action take with respect to which "reason code" is involved, if such action is needed. > > The main advantage of using reasonCodes over using a "class per error condition" is that you can reduce the size of the Exception hierarchy to a manageable size (GemStone has hundreds of error conditions, so we've resorted to using "reason codes" to manage the size of the hierarchy). > > As Hernan hints, more often than not it is important to be very specific about the error condition when signalling an error (a unique error message per "per reason code" would be desirable), but the there are very few places where the handler is going to be that specific ... > > In other words, if it is likely that programmers in the course of using an application will be writing specific error handlers to distinguish between the KeyNotFound and ValueNotFound condition, then classes should be created, otherwise, the NotFoundException could be implemented with three reason codes: #keyNotFound, #valueNotFound, and #elementNotFound and you'd get the best of both worlds, explicit information at the signalling site and a much smaller and more manageable Exception class hierarchy. > > Dale > > On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >> I think it is not a good idea to use the prefix Exception. We do not use >> the word "exception" in real life, so we should not do it on our systems. >> About the proposed hierarchy, the problem with having specific >> exceptions is that they are important for those who catch them, not for >> those who signal them. For example, besides the name, what is the >> difference between KeyNotFound or ValueNotFound? none. So, I think that >> the exception hierarchy should be grown from it uses, not created based >> on how or where they are signaled. >> >> my 2 cents :-) >> >> On Wed, Apr 13, 2011 at 1:55 PM, Miguel Cobá <[hidden email] >> <mailto:[hidden email]>> wrote: >> >> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >> >> > And as Mariano pointed out, there should be a convention on the >> > naming: I am still not sure about suffixing the exception classes >> with >> > "Exception", but I guess this is a good thing to do. Though I >> must say >> > that I omitted it so far ;) and just put the verb there, but that can >> > be easily changed. >> >> I would say no to suffixes. Analogous to announcements, they shouldn't >> have the suffix. The name should be descriptive enough and intention >> revealing that the suffix isn't needed in most cases. For example, I >> think that >> >> DividedByZero >> >> is better than >> >> DividedByZeroException >> >> and no information is lost with the sorter name. Instead, DivideByZero >> isn't clear enough to indicate that is a event that happened. >> >> What do you think? >> >> -- >> Miguel Cobá >> http://twitter.com/MiguelCobaMtz >> http://miguel.leugim.com.mx >> >> >> >> >> >> >> >> -- >> *Hernán Wilkinson >> Agile Software Development, Teaching & Coaching >> Mobile: +54 - 911 - 4470 - 7207 >> email: [hidden email] >> site: http://www.10Pines.com <http://www.10pines.com/>* >> > > |
Perfect, I ll be there to bang heads ;).
So without "Exception" pre- or suffix seems to be nice. However I don't see the need of using symbols over real classes. This feels indeed like going to stone age of error handling, thats what you have polymorphism and ExceptionSets for. Anyway, the main idea is to make single exceptions recognizable and not just use one single, basically meaningless, exception type. best regards, Camillo Bruni On 2011-04-13, at 21:22, Sven Van Caekenberghe wrote: > Thanks a lot everybody for the reactions, this could become a nice discussion next Friday. > All points raised are valid, I would like simple names and a compact multipurpose hierarchy too. > > On 13 Apr 2011, at 19:39, Dale Henrichs wrote: > >> Some thoughts from an old man (started programming before exceptions of any kind were available:) ... >> >> In the old days, error numbers had a place in the universe ... error numbers of a certain range indicated specific errors and the "error handlers" could check for a range or a specific error ... >> >> Today I think there is still a place for the notion of "error numbers". >> >> In Smalltalk I would use Symbols instead of numbers, but the idea would be to use a concrete exception class to identify broad categories of error conditions (i.e., FileStreamError) and a symbolic "reason code" to indicate the specific error (i.e., #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an error handler can be written for FileStreamError and then specific action take with respect to which "reason code" is involved, if such action is needed. >> >> The main advantage of using reasonCodes over using a "class per error condition" is that you can reduce the size of the Exception hierarchy to a manageable size (GemStone has hundreds of error conditions, so we've resorted to using "reason codes" to manage the size of the hierarchy). >> >> As Hernan hints, more often than not it is important to be very specific about the error condition when signalling an error (a unique error message per "per reason code" would be desirable), but the there are very few places where the handler is going to be that specific ... >> >> In other words, if it is likely that programmers in the course of using an application will be writing specific error handlers to distinguish between the KeyNotFound and ValueNotFound condition, then classes should be created, otherwise, the NotFoundException could be implemented with three reason codes: #keyNotFound, #valueNotFound, and #elementNotFound and you'd get the best of both worlds, explicit information at the signalling site and a much smaller and more manageable Exception class hierarchy. >> >> Dale >> >> On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >>> I think it is not a good idea to use the prefix Exception. We do not use >>> the word "exception" in real life, so we should not do it on our systems. >>> About the proposed hierarchy, the problem with having specific >>> exceptions is that they are important for those who catch them, not for >>> those who signal them. For example, besides the name, what is the >>> difference between KeyNotFound or ValueNotFound? none. So, I think that >>> the exception hierarchy should be grown from it uses, not created based >>> on how or where they are signaled. >>> >>> my 2 cents :-) >>> >>> On Wed, Apr 13, 2011 at 1:55 PM, Miguel Cobá <[hidden email] >>> <mailto:[hidden email]>> wrote: >>> >>> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >>> >>>> And as Mariano pointed out, there should be a convention on the >>>> naming: I am still not sure about suffixing the exception classes >>> with >>>> "Exception", but I guess this is a good thing to do. Though I >>> must say >>>> that I omitted it so far ;) and just put the verb there, but that can >>>> be easily changed. >>> >>> I would say no to suffixes. Analogous to announcements, they shouldn't >>> have the suffix. The name should be descriptive enough and intention >>> revealing that the suffix isn't needed in most cases. For example, I >>> think that >>> >>> DividedByZero >>> >>> is better than >>> >>> DividedByZeroException >>> >>> and no information is lost with the sorter name. Instead, DivideByZero >>> isn't clear enough to indicate that is a event that happened. >>> >>> What do you think? >>> >>> -- >>> Miguel Cobá >>> http://twitter.com/MiguelCobaMtz >>> http://miguel.leugim.com.mx >>> >>> >>> >>> >>> >>> >>> >>> -- >>> *Hernán Wilkinson >>> Agile Software Development, Teaching & Coaching >>> Mobile: +54 - 911 - 4470 - 7207 >>> email: [hidden email] >>> site: http://www.10Pines.com <http://www.10pines.com/>* >>> >> >> > > |
Camillo,
Hey, I _am_ old, but not _that_ old:) ... There are a couple of things that were invented in the Stone Age that have survived to today, so old ideas are not immediately bad, because they are old:) It feels like you are creating classes that are not much more than symbols ... I am not one to shy away from using classes when they are called for, but I am just making a practicality point ... we don't have a unique class for each character in the alphabet, but we could....we could have a unique class for every possible error condition or not ... I think it is simply a practical answer... I do maintain that you _should_ use some sort of test along the lines of: "Will anyone ever need to write a handler for the exception?" in your criteria for deciding when to create a class and when to use something like a "reason code" to disambiguate the signalling site... Dale On 04/13/2011 12:32 PM, Camillo Bruni wrote: > Perfect, I ll be there to bang heads ;). > > So without "Exception" pre- or suffix seems to be nice. However I > don't see the need of using symbols over real classes. This feels > indeed like going to stone age of error handling, thats what you have > polymorphism and ExceptionSets for. > > Anyway, the main idea is to make single exceptions recognizable and > not just use one single, basically meaningless, exception type. > > best regards, Camillo Bruni > > > On 2011-04-13, at 21:22, Sven Van Caekenberghe wrote: > >> Thanks a lot everybody for the reactions, this could become a nice >> discussion next Friday. All points raised are valid, I would like >> simple names and a compact multipurpose hierarchy too. >> >> On 13 Apr 2011, at 19:39, Dale Henrichs wrote: >> >>> Some thoughts from an old man (started programming before >>> exceptions of any kind were available:) ... >>> >>> In the old days, error numbers had a place in the universe ... >>> error numbers of a certain range indicated specific errors and >>> the "error handlers" could check for a range or a specific error >>> ... >>> >>> Today I think there is still a place for the notion of "error >>> numbers". >>> >>> In Smalltalk I would use Symbols instead of numbers, but the idea >>> would be to use a concrete exception class to identify broad >>> categories of error conditions (i.e., FileStreamError) and a >>> symbolic "reason code" to indicate the specific error (i.e., >>> #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an >>> error handler can be written for FileStreamError and then >>> specific action take with respect to which "reason code" is >>> involved, if such action is needed. >>> >>> The main advantage of using reasonCodes over using a "class per >>> error condition" is that you can reduce the size of the Exception >>> hierarchy to a manageable size (GemStone has hundreds of error >>> conditions, so we've resorted to using "reason codes" to manage >>> the size of the hierarchy). >>> >>> As Hernan hints, more often than not it is important to be very >>> specific about the error condition when signalling an error (a >>> unique error message per "per reason code" would be desirable), >>> but the there are very few places where the handler is going to >>> be that specific ... >>> >>> In other words, if it is likely that programmers in the course of >>> using an application will be writing specific error handlers to >>> distinguish between the KeyNotFound and ValueNotFound condition, >>> then classes should be created, otherwise, the NotFoundException >>> could be implemented with three reason codes: #keyNotFound, >>> #valueNotFound, and #elementNotFound and you'd get the best of >>> both worlds, explicit information at the signalling site and a >>> much smaller and more manageable Exception class hierarchy. >>> >>> Dale >>> >>> On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >>>> I think it is not a good idea to use the prefix Exception. We >>>> do not use the word "exception" in real life, so we should not >>>> do it on our systems. About the proposed hierarchy, the problem >>>> with having specific exceptions is that they are important for >>>> those who catch them, not for those who signal them. For >>>> example, besides the name, what is the difference between >>>> KeyNotFound or ValueNotFound? none. So, I think that the >>>> exception hierarchy should be grown from it uses, not created >>>> based on how or where they are signaled. >>>> >>>> my 2 cents :-) >>>> >>>> On Wed, Apr 13, 2011 at 1:55 PM, Miguel >>>> Cobá<[hidden email] <mailto:[hidden email]>> >>>> wrote: >>>> >>>> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >>>> >>>>> And as Mariano pointed out, there should be a convention on >>>>> the naming: I am still not sure about suffixing the exception >>>>> classes >>>> with >>>>> "Exception", but I guess this is a good thing to do. Though >>>>> I >>>> must say >>>>> that I omitted it so far ;) and just put the verb there, but >>>>> that can be easily changed. >>>> >>>> I would say no to suffixes. Analogous to announcements, they >>>> shouldn't have the suffix. The name should be descriptive >>>> enough and intention revealing that the suffix isn't needed in >>>> most cases. For example, I think that >>>> >>>> DividedByZero >>>> >>>> is better than >>>> >>>> DividedByZeroException >>>> >>>> and no information is lost with the sorter name. Instead, >>>> DivideByZero isn't clear enough to indicate that is a event >>>> that happened. >>>> >>>> What do you think? >>>> >>>> -- Miguel Cobá http://twitter.com/MiguelCobaMtz >>>> http://miguel.leugim.com.mx >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> -- *Hernán Wilkinson Agile Software Development, Teaching& >>>> Coaching Mobile: +54 - 911 - 4470 - 7207 email: >>>> [hidden email] site: >>>> http://www.10Pines.com<http://www.10pines.com/>* >>>> >>> >>> >> >> > > |
In reply to this post by Dale Henrichs
I completely agree with what Dale is saying... if you look at Patagonia (is on squeak source) you will see a package call Patagonia-AssertionsModel where I use something similar (if not the same) as Dale is saying... That package reifies different types of assertions, but when an assertion fails, it only throws one exception... the problem is how to handle an specific assertion failure?... if you look at the method #asExceptionToHandle you will get it, but basically from the handler point of view you write:
[ bla bla bla ] on: #earlyRegistrationFeeShouldBeLessThanLateRegistrationFee asExceptionToHandle do: [ :anAssertionFailure | .... ] Doing so the exception hierarchy is really simple. But each assertion has a name (what Dale calls "error numbers" at the begining) so the assertion failure (the exception) knows the assertion that failed and therefore it can be identified by the assertion's name, and you don't need to have a class per exception.... (the cool thing is that the name of an assertion is automatically set with the name of the method you are creating the assertion in, hehe, so if you rename the "helper" method where you create the assertion, the rename refactoring takes care of renaming all the places where it is handle :-) )
Anyway, being able to extend the exception mechanism with this is another reason why Smalltalk will never die :-) On Wed, Apr 13, 2011 at 2:39 PM, Dale Henrichs <[hidden email]> wrote: Some thoughts from an old man (started programming before exceptions of any kind were available:) ... -- Hernán Wilkinson
Agile Software Development, Teaching & Coaching Mobile: +54 - 911 - 4470 - 7207 email: [hidden email] site: http://www.10Pines.com |
In reply to this post by Dale Henrichs
I find the "managing the exception hierarchy" a bit strange... Do you
really have to manage anything more than just normal classes? Every exception is related to a specific part of your code, just like other classes. What's wrong with creating hundreds of small classes wherever it's necessary? You might save a tiny bit of memory by using error codes or symbols, but I don't really see much more of a gain there, while you do gain from proper objects. Being clear and modeling properly generally pays off in the long run. And the bit of runtime memory you save isn't really worth your while... Or am I missing something else? I didn't really follow the whole conversation in-depth. cheers, Toon On 04/13/2011 09:54 PM, Dale Henrichs wrote: > Camillo, > > Hey, I _am_ old, but not _that_ old:) ... There are a couple of things > that were invented in the Stone Age that have survived to today, so > old ideas are not immediately bad, because they are old:) > > It feels like you are creating classes that are not much more than > symbols ... > > I am not one to shy away from using classes when they are called for, > but I am just making a practicality point ... we don't have a unique > class for each character in the alphabet, but we could....we could > have a unique class for every possible error condition or not ... > > I think it is simply a practical answer... > > I do maintain that you _should_ use some sort of test along the lines > of: "Will anyone ever need to write a handler for the exception?" in > your criteria for deciding when to create a class and when to use > something like a "reason code" to disambiguate the signalling site... > > Dale > > On 04/13/2011 12:32 PM, Camillo Bruni wrote: >> Perfect, I ll be there to bang heads ;). >> >> So without "Exception" pre- or suffix seems to be nice. However I >> don't see the need of using symbols over real classes. This feels >> indeed like going to stone age of error handling, thats what you have >> polymorphism and ExceptionSets for. >> >> Anyway, the main idea is to make single exceptions recognizable and >> not just use one single, basically meaningless, exception type. >> >> best regards, Camillo Bruni >> >> >> On 2011-04-13, at 21:22, Sven Van Caekenberghe wrote: >> >>> Thanks a lot everybody for the reactions, this could become a nice >>> discussion next Friday. All points raised are valid, I would like >>> simple names and a compact multipurpose hierarchy too. >>> >>> On 13 Apr 2011, at 19:39, Dale Henrichs wrote: >>> >>>> Some thoughts from an old man (started programming before >>>> exceptions of any kind were available:) ... >>>> >>>> In the old days, error numbers had a place in the universe ... >>>> error numbers of a certain range indicated specific errors and >>>> the "error handlers" could check for a range or a specific error >>>> ... >>>> >>>> Today I think there is still a place for the notion of "error >>>> numbers". >>>> >>>> In Smalltalk I would use Symbols instead of numbers, but the idea >>>> would be to use a concrete exception class to identify broad >>>> categories of error conditions (i.e., FileStreamError) and a >>>> symbolic "reason code" to indicate the specific error (i.e., >>>> #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an >>>> error handler can be written for FileStreamError and then >>>> specific action take with respect to which "reason code" is >>>> involved, if such action is needed. >>>> >>>> The main advantage of using reasonCodes over using a "class per >>>> error condition" is that you can reduce the size of the Exception >>>> hierarchy to a manageable size (GemStone has hundreds of error >>>> conditions, so we've resorted to using "reason codes" to manage >>>> the size of the hierarchy). >>>> >>>> As Hernan hints, more often than not it is important to be very >>>> specific about the error condition when signalling an error (a >>>> unique error message per "per reason code" would be desirable), >>>> but the there are very few places where the handler is going to >>>> be that specific ... >>>> >>>> In other words, if it is likely that programmers in the course of >>>> using an application will be writing specific error handlers to >>>> distinguish between the KeyNotFound and ValueNotFound condition, >>>> then classes should be created, otherwise, the NotFoundException >>>> could be implemented with three reason codes: #keyNotFound, >>>> #valueNotFound, and #elementNotFound and you'd get the best of >>>> both worlds, explicit information at the signalling site and a >>>> much smaller and more manageable Exception class hierarchy. >>>> >>>> Dale >>>> >>>> On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >>>>> I think it is not a good idea to use the prefix Exception. We >>>>> do not use the word "exception" in real life, so we should not >>>>> do it on our systems. About the proposed hierarchy, the problem >>>>> with having specific exceptions is that they are important for >>>>> those who catch them, not for those who signal them. For >>>>> example, besides the name, what is the difference between >>>>> KeyNotFound or ValueNotFound? none. So, I think that the >>>>> exception hierarchy should be grown from it uses, not created >>>>> based on how or where they are signaled. >>>>> >>>>> my 2 cents :-) >>>>> >>>>> On Wed, Apr 13, 2011 at 1:55 PM, Miguel >>>>> Cobá<[hidden email] <mailto:[hidden email]>> >>>>> wrote: >>>>> >>>>> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >>>>> >>>>>> And as Mariano pointed out, there should be a convention on >>>>>> the naming: I am still not sure about suffixing the exception >>>>>> classes >>>>> with >>>>>> "Exception", but I guess this is a good thing to do. Though >>>>>> I >>>>> must say >>>>>> that I omitted it so far ;) and just put the verb there, but >>>>>> that can be easily changed. >>>>> >>>>> I would say no to suffixes. Analogous to announcements, they >>>>> shouldn't have the suffix. The name should be descriptive >>>>> enough and intention revealing that the suffix isn't needed in >>>>> most cases. For example, I think that >>>>> >>>>> DividedByZero >>>>> >>>>> is better than >>>>> >>>>> DividedByZeroException >>>>> >>>>> and no information is lost with the sorter name. Instead, >>>>> DivideByZero isn't clear enough to indicate that is a event >>>>> that happened. >>>>> >>>>> What do you think? >>>>> >>>>> -- Miguel Cobá http://twitter.com/MiguelCobaMtz >>>>> http://miguel.leugim.com.mx >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> -- *Hernán Wilkinson Agile Software Development, Teaching& >>>>> Coaching Mobile: +54 - 911 - 4470 - 7207 email: >>>>> [hidden email] site: >>>>> http://www.10Pines.com<http://www.10pines.com/>* >>>>> >>>> >>>> >>> >>> >> >> > > |
What's wrong is simple to explain: Your image is a namespace. The more
names you have, the more difficult it is to apprehend, understand and reuse. Wait, wait, wait, you might say, whether I use Symbols or Class names, there are always the same number of names at the end. Yes, but what makes the big difference is the IDE. What we see thru this IDE is either: - a view by package or protocol - a hierarchical view. How to find if a specific Exception exists, what it's name is ? By now, I find package names misleading, because not very uniform. Even if uniformized, it's not always obvious where to search for. Plus, there are a lot of packages. The hierarchical view would be more natural, but is to my taste unusable above 30 items. I find current Exception hierarchy unfriendly. So the idea to use a double classification, a quite generic exception name like FileError and a specialization "code" does make sense. You must understand this, when our neurons were younger, we learnt Smalltalk with a ~300 classes image. What a great pleasure to be able to embrace the whole system ! Now our older neurons must remember about 8x more... So we appreciate the inflation with a different scale. Nicolas 2011/4/13 Toon Verwaest <[hidden email]>: > I find the "managing the exception hierarchy" a bit strange... Do you really > have to manage anything more than just normal classes? Every exception is > related to a specific part of your code, just like other classes. What's > wrong with creating hundreds of small classes wherever it's necessary? You > might save a tiny bit of memory by using error codes or symbols, but I don't > really see much more of a gain there, while you do gain from proper objects. > > Being clear and modeling properly generally pays off in the long run. And > the bit of runtime memory you save isn't really worth your while... > > Or am I missing something else? I didn't really follow the whole > conversation in-depth. > > cheers, > Toon > > On 04/13/2011 09:54 PM, Dale Henrichs wrote: >> >> Camillo, >> >> Hey, I _am_ old, but not _that_ old:) ... There are a couple of things >> that were invented in the Stone Age that have survived to today, so old >> ideas are not immediately bad, because they are old:) >> >> It feels like you are creating classes that are not much more than symbols >> ... >> >> I am not one to shy away from using classes when they are called for, but >> I am just making a practicality point ... we don't have a unique class for >> each character in the alphabet, but we could....we could have a unique class >> for every possible error condition or not ... >> >> I think it is simply a practical answer... >> >> I do maintain that you _should_ use some sort of test along the lines of: >> "Will anyone ever need to write a handler for the exception?" in your >> criteria for deciding when to create a class and when to use something like >> a "reason code" to disambiguate the signalling site... >> >> Dale >> >> On 04/13/2011 12:32 PM, Camillo Bruni wrote: >>> >>> Perfect, I ll be there to bang heads ;). >>> >>> So without "Exception" pre- or suffix seems to be nice. However I >>> don't see the need of using symbols over real classes. This feels >>> indeed like going to stone age of error handling, thats what you have >>> polymorphism and ExceptionSets for. >>> >>> Anyway, the main idea is to make single exceptions recognizable and >>> not just use one single, basically meaningless, exception type. >>> >>> best regards, Camillo Bruni >>> >>> >>> On 2011-04-13, at 21:22, Sven Van Caekenberghe wrote: >>> >>>> Thanks a lot everybody for the reactions, this could become a nice >>>> discussion next Friday. All points raised are valid, I would like >>>> simple names and a compact multipurpose hierarchy too. >>>> >>>> On 13 Apr 2011, at 19:39, Dale Henrichs wrote: >>>> >>>>> Some thoughts from an old man (started programming before >>>>> exceptions of any kind were available:) ... >>>>> >>>>> In the old days, error numbers had a place in the universe ... >>>>> error numbers of a certain range indicated specific errors and >>>>> the "error handlers" could check for a range or a specific error >>>>> ... >>>>> >>>>> Today I think there is still a place for the notion of "error >>>>> numbers". >>>>> >>>>> In Smalltalk I would use Symbols instead of numbers, but the idea >>>>> would be to use a concrete exception class to identify broad >>>>> categories of error conditions (i.e., FileStreamError) and a >>>>> symbolic "reason code" to indicate the specific error (i.e., >>>>> #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an >>>>> error handler can be written for FileStreamError and then >>>>> specific action take with respect to which "reason code" is >>>>> involved, if such action is needed. >>>>> >>>>> The main advantage of using reasonCodes over using a "class per >>>>> error condition" is that you can reduce the size of the Exception >>>>> hierarchy to a manageable size (GemStone has hundreds of error >>>>> conditions, so we've resorted to using "reason codes" to manage >>>>> the size of the hierarchy). >>>>> >>>>> As Hernan hints, more often than not it is important to be very >>>>> specific about the error condition when signalling an error (a >>>>> unique error message per "per reason code" would be desirable), >>>>> but the there are very few places where the handler is going to >>>>> be that specific ... >>>>> >>>>> In other words, if it is likely that programmers in the course of >>>>> using an application will be writing specific error handlers to >>>>> distinguish between the KeyNotFound and ValueNotFound condition, >>>>> then classes should be created, otherwise, the NotFoundException >>>>> could be implemented with three reason codes: #keyNotFound, >>>>> #valueNotFound, and #elementNotFound and you'd get the best of >>>>> both worlds, explicit information at the signalling site and a >>>>> much smaller and more manageable Exception class hierarchy. >>>>> >>>>> Dale >>>>> >>>>> On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >>>>>> >>>>>> I think it is not a good idea to use the prefix Exception. We >>>>>> do not use the word "exception" in real life, so we should not >>>>>> do it on our systems. About the proposed hierarchy, the problem >>>>>> with having specific exceptions is that they are important for >>>>>> those who catch them, not for those who signal them. For >>>>>> example, besides the name, what is the difference between >>>>>> KeyNotFound or ValueNotFound? none. So, I think that the >>>>>> exception hierarchy should be grown from it uses, not created >>>>>> based on how or where they are signaled. >>>>>> >>>>>> my 2 cents :-) >>>>>> >>>>>> On Wed, Apr 13, 2011 at 1:55 PM, Miguel >>>>>> Cobá<[hidden email] <mailto:[hidden email]>> >>>>>> wrote: >>>>>> >>>>>> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >>>>>> >>>>>>> And as Mariano pointed out, there should be a convention on >>>>>>> the naming: I am still not sure about suffixing the exception >>>>>>> classes >>>>>> >>>>>> with >>>>>>> >>>>>>> "Exception", but I guess this is a good thing to do. Though >>>>>>> I >>>>>> >>>>>> must say >>>>>>> >>>>>>> that I omitted it so far ;) and just put the verb there, but >>>>>>> that can be easily changed. >>>>>> >>>>>> I would say no to suffixes. Analogous to announcements, they >>>>>> shouldn't have the suffix. The name should be descriptive >>>>>> enough and intention revealing that the suffix isn't needed in >>>>>> most cases. For example, I think that >>>>>> >>>>>> DividedByZero >>>>>> >>>>>> is better than >>>>>> >>>>>> DividedByZeroException >>>>>> >>>>>> and no information is lost with the sorter name. Instead, >>>>>> DivideByZero isn't clear enough to indicate that is a event >>>>>> that happened. >>>>>> >>>>>> What do you think? >>>>>> >>>>>> -- Miguel Cobá http://twitter.com/MiguelCobaMtz >>>>>> http://miguel.leugim.com.mx >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- *Hernán Wilkinson Agile Software Development, Teaching& >>>>>> Coaching Mobile: +54 - 911 - 4470 - 7207 email: >>>>>> [hidden email] site: >>>>>> http://www.10Pines.com<http://www.10pines.com/>* >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > > |
In reply to this post by Toon Verwaest-2
By managing the class hierarchy:
Imagine trying to find meaningful exception classes in a class hierarchy of 10,000 classes with significant nesting vs finding a meaningful class in a hierarchy of 10 classes ... at what point does the hierarchy get out of hand? I think GemStone had 600 some unique errors and that was pared down to <30 Exception classes with reason codes... It's a matter of practicality...I would think that somewhere around 100 classes the hierarchy starts to become very tedious to understand even for those trying to find the right place to insert there brand spanking new exception class. 99% of exception handlers will _use_ Error_ anyway, so the exception hierarchy will be largely ignored by most folks, especially if it is large an unwieldly. 100 small classes that serve a real purpose and have explicit exception handlers written using every one of them, well then by god! 100 classes are absolutely called for. To me this is different than 100 places where I signal an exception ... do really need a different exception class for each of the 100 signalling sites? What if there are no handlers written for any of them? Like I said, if there are legitimate need to handle an exception, then there is a legitimate need to create an exception class, but if I have 5 different error conditions, but I will have a single exception handler for all 5 conditions, _should_ I create 5 classes or 1 class with some state to disambiguate? If your answer is "It depends...", then you will understand what I am saying:) Dale On 04/13/2011 02:01 PM, Toon Verwaest wrote: > I find the "managing the exception hierarchy" a bit strange... Do you > really have to manage anything more than just normal classes? Every > exception is related to a specific part of your code, just like other > classes. What's wrong with creating hundreds of small classes wherever > it's necessary? You might save a tiny bit of memory by using error codes > or symbols, but I don't really see much more of a gain there, while you > do gain from proper objects. > > Being clear and modeling properly generally pays off in the long run. > And the bit of runtime memory you save isn't really worth your while... > > Or am I missing something else? I didn't really follow the whole > conversation in-depth. > > cheers, > Toon > > On 04/13/2011 09:54 PM, Dale Henrichs wrote: >> Camillo, >> >> Hey, I _am_ old, but not _that_ old:) ... There are a couple of things >> that were invented in the Stone Age that have survived to today, so >> old ideas are not immediately bad, because they are old:) >> >> It feels like you are creating classes that are not much more than >> symbols ... >> >> I am not one to shy away from using classes when they are called for, >> but I am just making a practicality point ... we don't have a unique >> class for each character in the alphabet, but we could....we could >> have a unique class for every possible error condition or not ... >> >> I think it is simply a practical answer... >> >> I do maintain that you _should_ use some sort of test along the lines >> of: "Will anyone ever need to write a handler for the exception?" in >> your criteria for deciding when to create a class and when to use >> something like a "reason code" to disambiguate the signalling site... >> >> Dale >> >> On 04/13/2011 12:32 PM, Camillo Bruni wrote: >>> Perfect, I ll be there to bang heads ;). >>> >>> So without "Exception" pre- or suffix seems to be nice. However I >>> don't see the need of using symbols over real classes. This feels >>> indeed like going to stone age of error handling, thats what you have >>> polymorphism and ExceptionSets for. >>> >>> Anyway, the main idea is to make single exceptions recognizable and >>> not just use one single, basically meaningless, exception type. >>> >>> best regards, Camillo Bruni >>> >>> >>> On 2011-04-13, at 21:22, Sven Van Caekenberghe wrote: >>> >>>> Thanks a lot everybody for the reactions, this could become a nice >>>> discussion next Friday. All points raised are valid, I would like >>>> simple names and a compact multipurpose hierarchy too. >>>> >>>> On 13 Apr 2011, at 19:39, Dale Henrichs wrote: >>>> >>>>> Some thoughts from an old man (started programming before >>>>> exceptions of any kind were available:) ... >>>>> >>>>> In the old days, error numbers had a place in the universe ... >>>>> error numbers of a certain range indicated specific errors and >>>>> the "error handlers" could check for a range or a specific error >>>>> ... >>>>> >>>>> Today I think there is still a place for the notion of "error >>>>> numbers". >>>>> >>>>> In Smalltalk I would use Symbols instead of numbers, but the idea >>>>> would be to use a concrete exception class to identify broad >>>>> categories of error conditions (i.e., FileStreamError) and a >>>>> symbolic "reason code" to indicate the specific error (i.e., >>>>> #fileDoesNotExist, #fileExists, #cannotDelete, etc.), that way an >>>>> error handler can be written for FileStreamError and then >>>>> specific action take with respect to which "reason code" is >>>>> involved, if such action is needed. >>>>> >>>>> The main advantage of using reasonCodes over using a "class per >>>>> error condition" is that you can reduce the size of the Exception >>>>> hierarchy to a manageable size (GemStone has hundreds of error >>>>> conditions, so we've resorted to using "reason codes" to manage >>>>> the size of the hierarchy). >>>>> >>>>> As Hernan hints, more often than not it is important to be very >>>>> specific about the error condition when signalling an error (a >>>>> unique error message per "per reason code" would be desirable), >>>>> but the there are very few places where the handler is going to >>>>> be that specific ... >>>>> >>>>> In other words, if it is likely that programmers in the course of >>>>> using an application will be writing specific error handlers to >>>>> distinguish between the KeyNotFound and ValueNotFound condition, >>>>> then classes should be created, otherwise, the NotFoundException >>>>> could be implemented with three reason codes: #keyNotFound, >>>>> #valueNotFound, and #elementNotFound and you'd get the best of >>>>> both worlds, explicit information at the signalling site and a >>>>> much smaller and more manageable Exception class hierarchy. >>>>> >>>>> Dale >>>>> >>>>> On 04/13/2011 10:15 AM, Hernan Wilkinson wrote: >>>>>> I think it is not a good idea to use the prefix Exception. We >>>>>> do not use the word "exception" in real life, so we should not >>>>>> do it on our systems. About the proposed hierarchy, the problem >>>>>> with having specific exceptions is that they are important for >>>>>> those who catch them, not for those who signal them. For >>>>>> example, besides the name, what is the difference between >>>>>> KeyNotFound or ValueNotFound? none. So, I think that the >>>>>> exception hierarchy should be grown from it uses, not created >>>>>> based on how or where they are signaled. >>>>>> >>>>>> my 2 cents :-) >>>>>> >>>>>> On Wed, Apr 13, 2011 at 1:55 PM, Miguel >>>>>> Cobá<[hidden email]<mailto:[hidden email]>> >>>>>> wrote: >>>>>> >>>>>> El mié, 13-04-2011 a las 14:52 +0200, Camillo Bruni escribió: >>>>>> >>>>>>> And as Mariano pointed out, there should be a convention on >>>>>>> the naming: I am still not sure about suffixing the exception >>>>>>> classes >>>>>> with >>>>>>> "Exception", but I guess this is a good thing to do. Though >>>>>>> I >>>>>> must say >>>>>>> that I omitted it so far ;) and just put the verb there, but >>>>>>> that can be easily changed. >>>>>> >>>>>> I would say no to suffixes. Analogous to announcements, they >>>>>> shouldn't have the suffix. The name should be descriptive >>>>>> enough and intention revealing that the suffix isn't needed in >>>>>> most cases. For example, I think that >>>>>> >>>>>> DividedByZero >>>>>> >>>>>> is better than >>>>>> >>>>>> DividedByZeroException >>>>>> >>>>>> and no information is lost with the sorter name. Instead, >>>>>> DivideByZero isn't clear enough to indicate that is a event >>>>>> that happened. >>>>>> >>>>>> What do you think? >>>>>> >>>>>> -- Miguel Cobá http://twitter.com/MiguelCobaMtz >>>>>> http://miguel.leugim.com.mx >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- *Hernán Wilkinson Agile Software Development, Teaching& >>>>>> Coaching Mobile: +54 - 911 - 4470 - 7207 email: >>>>>> [hidden email] site: >>>>>> http://www.10Pines.com<http://www.10pines.com/>* >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > |
Free forum by Nabble | Edit this page |