[fpc-pascal] Standard exceptions

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Feb 28 18:28:37 CET 2011


On 28 Feb 2011, at 13:51, Michael Fuchs wrote:

> while porting software from .NET to FreePascal I am looking for some exceptions for recurrent errors. For example:
> 
> ArgumentException, ArgumentNullException, ArgumentOutOfRangeException

None of these exist in Pascal. You can get exceptions for range check errors (ERangeError) in case you enable range checking and include the sysutils unit in your uses clause, but in that case range checking will be performed for all assignments, not just for passed arguments (and the range is checked by the compiler at the caller side based on the declared parameter types, not at the callee side). There are only a few routines in the RTL that explicitly raise it after explicitly checking their arguments.

There are no generic equivalents to ArgumentException and ArgumentNullException (when asking such questions in the future, you may also want to include a reference to a web page that describes what they mean, it makes it easier for people to answer you).

> Is there a unit which defines those exceptions?

Most general exception types are defined in the sysutils unit. In many cases, routines return an error code rather than throwing an exception though. And if they throw an exception, it's quite likely that it's specific to that routine rather than of some generic type. The FPC manuals list per routine what happens in case of errors.


Jonas


More information about the fpc-pascal mailing list