Standard exceptions

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Standard exceptions

Michael Fuchs-5
Hello,

while porting software from .NET to FreePascal I am looking for some
exceptions for recurrent errors. For example:

ArgumentException, ArgumentNullException, ArgumentOutOfRangeException

Is there a unit which defines those exceptions?

regards
Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Marcos Douglas B. Santos
On Mon, Feb 28, 2011 at 9:51 AM, Michael Fuchs
<[hidden email]> wrote:
> Hello,
>
> while porting software from .NET to FreePascal I am looking for some
> exceptions for recurrent errors. For example:
>
> ArgumentException, ArgumentNullException, ArgumentOutOfRangeException
>
> Is there a unit which defines those exceptions?

I never heard anybody said do this conversion...
Well, do not exists these Classes in FPC. Not exists a place for all
Exception classes but the first classe to exceptions is declared in
SysUtils unit.


Marcos Douglas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Sven Barth-2
In reply to this post by Michael Fuchs-5
Am 28.02.2011 13:51, schrieb Michael Fuchs:
> Hello,
>
> while porting software from .NET to FreePascal I am looking for some
> exceptions for recurrent errors. For example:
>
> ArgumentException, ArgumentNullException, ArgumentOutOfRangeException
>
> Is there a unit which defines those exceptions?

As far as I'm aware of: There are none.

There is ERangeError though (in SysUtils), but that's not an equivalent
for ArgumentOutOfRangeException (I suppose that inherits from
ArgumentException?).

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

michael.vancanneyt
In reply to this post by Michael Fuchs-5


On Mon, 28 Feb 2011, Michael Fuchs wrote:

> Hello,
>
> while porting software from .NET to FreePascal I am looking for some
> exceptions for recurrent errors. For example:
>
> ArgumentException, ArgumentNullException, ArgumentOutOfRangeException
>
> Is there a unit which defines those exceptions?

These exact exceptions are not defined. The SysUtils unit defines the most
standard exceptions, as well as the Classes unit.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Jonas Maebe-2
In reply to this post by Michael Fuchs-5

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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Michael Fuchs-5
In reply to this post by Sven Barth-2
Am 28.02.2011 14:17, schrieb Sven Barth:
> As far as I'm aware of: There are none.
>
> There is ERangeError though (in SysUtils), but that's not an equivalent
> for ArgumentOutOfRangeException (I suppose that inherits from
> ArgumentException?).

Yes,and all Argument..Exceptions have a property ParamName:String
containing the parameter which causes the error.

I also miss a NotImplementedException (or ENotImplemented in FPC style),
very handy for test driven development. :)

And by the way: how about a InnerException for the SysUtils.Exception
class? This would be nice if you want to wrap an exception around another.

Are there any chances for implement this?

regards
Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Vinzent Höfler
In reply to this post by Michael Fuchs-5
On Tue, 01 Mar 2011 12:38:27 +0100, Michael Fuchs  
<[hidden email]> wrote:

> I also miss a NotImplementedException (or ENotImplemented in FPC style),  
> very handy for test driven development. :)

Yeah. And

type
    //-- @abstract(Obvious coding error.)
    Coder_Needs_Coffee = class (SysUtils.Exception);

was very handy for those "me stupid" situations.

;)


Vinzent.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Michael Fuchs-5
In reply to this post by Jonas Maebe-2
Am 28.02.2011 18:28, schrieb Jonas Maebe:
> 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).

Sorry, bad mistake. A simple description of this exceptions or better of
their possible FPC equivalents:

EArgument
Base exception for argument related exceptions. Contains a property
ParamName which helds the parameter causing the error.

EArgumentNil (inherits from EArgument):
Thrown if a given parameter to a method is nil and should not.

EArgumentRange (inherits from EArgument):
Thrown if a given parameter to a method is out of range.

ENotImplemented
Thrown if a method implementation is not ready. Nice for
test-driven-development. Maybe IDEs which generates class
implementations could start with a "raise ENotImplemted.Create;" in
method body.

regards
Michael
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Standard exceptions

Marco van de Voort
In reply to this post by Jonas Maebe-2
In our previous episode, Jonas Maebe said:
> 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).

C# has nullable types, and my guess would be that the ArgumentNullexception
happens you assign/pass a nullable value with NULL to a non-nullable
equivalent.

So it could be that it corresponds to some EVariantisnull error, but that is
a bit of a stretch.
 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal