< Erlang (programming language) | TutorialsRevision as of 12:26, 22 April 2008 by imported>Chris Day
The metadata subpage is missing. You can start it via filling in this form or by following the instructions that come up after clicking on the [show] link to the right.
|
Do you see this on PREVIEW? then SAVE! before following a link.
A - For a New Cluster use the following directions
Subpages format requires a metadata page.
Using the following instructions will complete the process of creating this article's subpages.
- Click the blue "metadata template" link below to create the page.
- On the edit page that appears paste in the article's title across from "
pagename = ".
- You might also fill out the checklist part of the form. Ignore the rest.
- For background, see Using the Subpages template Don't worry--you'll get the hang of it right away.
- Remember to hit Save!
the "metadata template".
However, you can create articles without subpages. Just delete the {{subpages}} template from the top of this page and this prompt will disappear. :) Don't feel obligated to use subpages, it's more important that you write sentences, which you can always do without writing fancy code.
|
B - For a Cluster Move use the following directions
The metadata template should be moved to the new name as the first step. Please revert this move and start by using the Move Cluster link at the top left of the talk page.
The name prior to this move can be found at the following link.
|
|
Errors
We can deal with errors with throw and catch. In this example the value of an argument causes an error which causes an exception to be thrown. The function g() is only happy when the argument is greater then 12. If the arguemnt is less than 13 then an exception is thrown. We try to call g() in start(). If we run into trouble then the exception is caught in the "case catch" structure inside of start().
Sample program listing:
-module(catch_it).
-compile(export_all).
%
% An example of throw and catch
%
g(X) when X >= 13 ->
ok;
g(X) when X < 13 ->
throw({exception1, bad_number}).
%
% Throw in g/1
% Catch in start/1
%
start(Input) ->
case catch g(Input) of
{exception1, Why} ->
io:format("trouble is ~w ", [ Why ]);
NormalReturnValue ->
io:format("good input ~w ", [ NormalReturnValue ] )
end.
%
%============================================================== >%
% sample output:
%
8> c(catch_it).
{ok,catch_it}
%
9> catch_it:start(12).
trouble is bad_number ok
%
10> catch_it:start(13).
good input ok ok