n3ss3s
08-01-2007, 04:08 PM
As the topic says.
Ever seen when you come from school, wake up in teh morning and your scar says something about runtime error and does nothing?
To avoid that, the creator of programming(who might that be?) has given us...
Try Except
There is 2 ways to get a script running good.
a) script right
b) script easy, right, and lazy.
The how to do the a option would be longer explanation, so I will explain the b one, the meaning of this tutorial - Try Except.
1. What is try except supposed to do?
Avoid runtime errors!
2. How to use it
Well, I'll make an example instead of explanation.
program new;
var
A: array of Integer;
begin
SetArrayLength(A, 3); // from 0 to 2
A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
end.
That program would give a runtime error when ran.
To avoid that we could use try except and do
program new;
var
A: array of Integer;
begin
SetArrayLength(A, 3); // from 0 to 2
try
A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
except
Writeln('Oh noes! We tried to edit array slot which is out of range!');
end;
end.
Basically what that script does, is sets array "A" length to 3 which means the thingys are 0, 1, 2 and we are trying to edit the 3 which doesnt exist.
Try part of try catch, tries to execute the part of the program between try and catch, its a bit like begin and end.
The part between except and end executes the part of the program which we have coded to do when our thing (in this case, the A[3] := 15) could not be executed.
In this case, it would write "Oh noes! We tried to edit array slot which is out of range!" to the scar debug box.
But, as many of you may think, if not, it ofcourse does not execute both the try and except part, because that'd be too leet.
This is pretty simple thing so I think I dont need to explain more.
Take the example code and play with it... (modify and learn)...
Thx
Ever seen when you come from school, wake up in teh morning and your scar says something about runtime error and does nothing?
To avoid that, the creator of programming(who might that be?) has given us...
Try Except
There is 2 ways to get a script running good.
a) script right
b) script easy, right, and lazy.
The how to do the a option would be longer explanation, so I will explain the b one, the meaning of this tutorial - Try Except.
1. What is try except supposed to do?
Avoid runtime errors!
2. How to use it
Well, I'll make an example instead of explanation.
program new;
var
A: array of Integer;
begin
SetArrayLength(A, 3); // from 0 to 2
A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
end.
That program would give a runtime error when ran.
To avoid that we could use try except and do
program new;
var
A: array of Integer;
begin
SetArrayLength(A, 3); // from 0 to 2
try
A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
except
Writeln('Oh noes! We tried to edit array slot which is out of range!');
end;
end.
Basically what that script does, is sets array "A" length to 3 which means the thingys are 0, 1, 2 and we are trying to edit the 3 which doesnt exist.
Try part of try catch, tries to execute the part of the program between try and catch, its a bit like begin and end.
The part between except and end executes the part of the program which we have coded to do when our thing (in this case, the A[3] := 15) could not be executed.
In this case, it would write "Oh noes! We tried to edit array slot which is out of range!" to the scar debug box.
But, as many of you may think, if not, it ofcourse does not execute both the try and except part, because that'd be too leet.
This is pretty simple thing so I think I dont need to explain more.
Take the example code and play with it... (modify and learn)...
Thx