Exceptions: Difference between revisions

added slate language
(add E example, at length)
(added slate language)
Line 859:
 
You can only "throw" and "catch" symbols. Like exceptions, the throw can be made from a function defined elsewhere from the catch block.
 
=={{header|Slate}}==
 
===Handling Exceptions===
 
<lang slate>
se@(SceneElement traits) doWithRestart: block
[
block handlingCases: {Abort -> [| :_ | ^ Nil]}
].
 
</lang>
 
===Define Exceptions===
 
<lang slate>
conditions define: #Abort &parents: {Restart}.
"An Abort is a Restart which exits the computation, unwinding the stack."
 
_@lobby abort
[
Abort signal
].
_@(Abort traits) describeOn: console
[
console ; 'Abort evaluation of expression\n'
].
 
"This will call:"
c@(Condition traits) signal
"Signalling a Condition."
[
c tryHandlers
].
 
</lang>
 
===Throwing Exceptions===
<lang slate>
(fileName endsWith: '.image') ifTrue: [error: 'Image filename specified where Slate source expected. Make sure you run slate with the -i flag to specify an image.'].
 
</lang>
 
 
=={{header|Standard ML}}==
Anonymous user