The Artima Developer Community
Sponsored Link

Agile Buzz Forum
When to make an Exception of an Exception?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
When to make an Exception of an Exception? Posted: Jul 9, 2004 3:46 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: When to make an Exception of an Exception?
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
With the ANSI exception stuff, the exception hierarchy is a good old class hierarchy. On my system, I get the following:

Class withAllSubclasses size
GenericException 200
Exception 189
Error 148

So, a good chunk of the classical exception set is put under Error. Here's the dilemma. When do you just use Error, and when do you make your own new Error sub type? The pro of just using Error is that you don't have to do anything new really. You just start using

self error: 'someErrorString'

The drawback is that if you need to trap and handle your special error, you have to handle it ambiguously with something like:

[self doMyThing] on: Error do: [:ex | self dealWithMySpecificError]

But what if there's a ZeroDivide signal that happens in there? It'll trap that too. Generally, I frown on trying to handle specific errors by trapping any type.

Apparently, this is a dilemma for the base image authors as well. Take Dictionary for example. It inherits from Collection four error raising messages:

  • emptyCollectionError
  • noMatchError
  • notFoundError
  • notKeyedError

It adds to that, two of its own:

  • keyNotFoundErrorFor:index:
  • valueNotFoundError:

The interesting thing about these 6 errors is that 3 of them raise specific errors (sub types of Error) and 3 of them don't. Can you guess which three? I couldn't. If you had to pick the three that deserved their own type of error, what would you choose. I ran into this, because I wanted to trap the EmptyCollectionError, but there isn't one. It's just a generic Error. Even more interesting to note is that the three that do raise their own signals all use different forms and APIs of actually getting the exception raised!

So this leaves me wondering, when I'm designing my own set of exceptions to raise, with an example like that, where do I look for examples of a good way to do it? What APIs to use? And when, and when not to just hijack Error instead of creating your own new one? What do others do? It makes me wonder what a newbies exposure to an "Exceptional" Smalltalk session is like.

(P.S: There are 725 senders of #error: in my system)

Read: When to make an Exception of an Exception?

Topic: Addendum to My BottomFeeder Wish List Previous Topic   Next Topic Topic: Heavy duty

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use