PDA

View Full Version : Try except handy for more than only files!



Master BAW
07-06-2012, 03:12 PM
Hey,
I read in a tutorial that the try..except statement only is usefull for files handling, but I have thought of something that makes it very usefull

for example you can have an array but sometimes a value should exsist but doesnt for some reason...

you then can do this:

program new;
var
x: array of integer;

begin

setLength(x,4);

x[0] := 4;
x[1] := 5;
x[2] := 1;
x[3] := 6;

Try
writeln(x[6]);
except
writeln('6 doesnt exsist');
end;


end.

I found this usefull and have never read this somewhere before so I share it ;)

Chris
07-06-2012, 04:03 PM
When you are writing a real script you will know, when writing it, that certain values won't be assigned and that you can avoid errors by using High() and Length()
This will still be nice to know for new scripters, but I don't think Ill use it.

Also, I live 30 minutes cycling away from you xD

Brandon
07-06-2012, 04:08 PM
It is useful for Bitmaps from Pointers. It isn't always exception safe though you can make it exception safe, it usually standard in other languages to either wrap a raw pointer in a smartpointer container or to wrap it in a try catch and debug upon the catch or pass it to a custom handler.

Simba now supports bitmaps from pointers. Try-Catch is used to stop unforseen exceptions that can throw in your script during runtime. It would probably stop most exceptions by users of your script incase they put something wrong that would cause a throw.

It's always handy for "Forms/GUIs" because those are running via threads and can throw unexpectedly.

Master BAW
07-08-2012, 12:22 PM
When you are writing a real script you will know, when writing it, that certain values won't be assigned and that you can avoid errors by using High() and Length()
This will still be nice to know for new scripters, but I don't think Ill use it.

Also, I live 30 minutes cycling away from you xD
Thanks for the tip, I now see that indeed I don't use very much high() nor length() .. :)
En welke plaats woon je dan? :p


It is useful for Bitmaps from Pointers. It isn't always exception safe though you can make it exception safe, it usually standard in other languages to either wrap a raw pointer in a smartpointer container or to wrap it in a try catch and debug upon the catch or pass it to a custom handler.
I don't understand this :p


Simba now supports bitmaps from pointers. Try-Catch is used to stop unforseen exceptions that can throw in your script during runtime. It would probably stop most exceptions by users of your script incase they put something wrong that would cause a throw.

It's always handy for "Forms/GUIs" because those are running via threads and can throw unexpectedly.
Ah, okay, thanks for the info:)

Chris
07-08-2012, 12:27 PM
Thanks for the tip, I now see that indeed I don't use very much high() nor length() .. :)
En welke plaats woon je dan? :p

Groningen!
See the SRL Map Of Members ;)
https://maps.google.com/maps/ms?vps=2&ie=UTF8&hl=en&oe=UTF8&msa=0&msid=212600793376838507366.0004c36a84078eebdb5ae

Master BAW
07-08-2012, 12:32 PM
Groningen!
See the SRL Map Of Members ;)
https://maps.google.com/maps/ms?vps=2&ie=UTF8&hl=en&oe=UTF8&msa=0&msid=212600793376838507366.0004c36a84078eebdb5ae

haha I didn't know I stood there on that map too :p I tried it but I thought I failed . Okay so you live less than 30 minites indeed ;)