[fpc-pascal] using exceptions
José Mejuto
joshyfun at gmail.com
Wed Jan 4 19:57:27 CET 2012
Hello FPC-Pascal,
Wednesday, January 4, 2012, 1:31:01 AM, you wrote:
MD> Very interesting and I agree when he say:
MD> "I think the reason programmers in C/C++/Java style languages have
MD> been attracted to exceptions is simply because the syntax does not
MD> have a concise way to call a function that returns multiple values, so
MD> it's hard to write a function that either produces a return value or
MD> returns an error."
MD> If we could return more than one value, ok we (maybe) do not need Exceptions.
No, because they are different concepts, an exception is a non
expected error, this means that the code where the exception has been
raised could or could not be anymore in a predictable state. Error are
controlled, the code will remain stable or not, but that information
is returned by the error code.
The example tryStrToInt can have an error code (expected and
controlled) and one exception, which is an error that could not be
reported as error, but produce a non stability situation.
tryStrToInt('ABCDEFGHIJKL') should return false;
tryStrToInt('12345678901234567890123456789012345678901234567890') can
produce an exception, overflow, because the number is fine, it is a
number, but it can not return the right value in 64 bits.
This is just an example, not a real situation.
--
Best regards,
José
More information about the fpc-pascal
mailing list