GNU Smalltalk: Difference between revisions

no edit summary
m (Use the implementation template, removed link to "hello world")
No edit summary
Line 115:
===Classes===
 
The following code defines a class named Person. By deriving from Magnitude, it automatically defines all comparison methods except one (<codett>&lt;</codett>). With the addition of that one, <codett>asSortedCollection</codett> can sort by age. Note that we can override the way the object is printed/displayed (the default is to share the programmer-print and user-display representation) by overriding <codett>printOn:</codett>.
 
Magnitude subclass: Person [
Line 144:
 
===Exceptions===
An exception is raised with a <codett>halt</codett> call:
 
self halt
 
An optional message can be added to the exception; there's also <codett>error:</codett> which raises a different kind of exception:
 
self halt: 'This is a message'
self error: 'This is a message'
 
These are actually wrappers for the actual exception raising method, <codett>signal>:
 
Error signal
Error signal: 'Illegal arguments!'
 
Exceptions are handled by <code>on:do:</codett> blocks.
 
[ something to do ]