3
votes
Vote UpVote

Think twice before raising exception in constructor

The Programming Works – Recently prolific Delphi writer Nick Hodges declared a war on the use of nil pointers. It is arguable whether nil pointers usage is bad or not, but the point is the “Guard Pattern” proposed is really an antipattern. Here is a simple demo: program Project11; {$APPTYPE CONSOLE} uses SysUtils, Classes; type TMyClass = class private FList: TStringList; public constructor Create(AList: TStringList); destructor Destroy; override; end; constructor TMyClass.Create(AList: TStringList); begin if AList = nil then begin raise Exception.Create('Don''t you dare ...
Favorite? Off-Topic? Serg @ 2015-01-21 10:45

Statistics

Visits: 753
Votes: 3
Favorites: 0
Off-Topic: 0

Visits by Source

User Actions

Users who voted for this posting

Delphster
NickHodges
TOndrej
Subscribe:
Contact us to advertise on DelphiFeeds.com

Community Links

Torry Firebird News

Sponsor

 
Please login or register to use this functionality.
(click on this box to dismiss)