weaselforce
2006-05-23 20:58:26
how does the "except" command work, Whenever I enter it into scar it becomes bold…i've never heard of this
2006-05-23 20:58:26
2006-05-23 21:04:44
2006-05-23 21:06:36
2006-05-23 21:13:16
var x, y: integer;
procedure Error;
begin
try
x:= 0/y;
Writeln(IntToStr(X));
except
Writeln('You just divided by 0');
end;
end;
begin
y:= 1;
Error;
y:= 0;
Error;
Writeln('We''re still running :)');
end.
2006-05-23 21:24:26
try
Sqrt(i);
except
Writeln('Cannot square root a negative number');
end;Since the script runs into an error upon finding a negative number in a sqrt function, you can make sure it skips the error using the try..except clause. Instead of doing the sqrt, it will Writeln('Cannot square root a negative number');. However, if the sqrt function does not cause an error, it skips the except step. Now, you can do things in the clauses like so (note, no begin..ends needed, except for the end at the end of the clause):try
Writeln('Only shown if there's no error');
Writeln('Note:');
Writeln('You can put as many things as you want here until the except/finally');
except
Writeln('Only shown if there was an error in the try section');
Writeln('Note:');
Writeln('You can put as many things as you want here until the finally/end');
finally
Writeln('This is shown whether or not there was an error in the try section');
Writeln('Note:');
Writeln('You can put as many things as you want here until the end');
end;I hope this has helped. A section on this subject will be in the next version of my Tutorial Project ;)2006-05-23 21:27:38
2006-05-23 21:27:44
2006-05-23 21:35:15
2006-05-23 21:45:06