Ceci est une ancienne révision du document !
Exception & Erreurs
La class
Exception = class(TObject) public constructor Create(const msg : string); constructor CreateFmt(const msg : string; const args : array of const); constructor CreateRes(ResString: PString); constructor CreateResFmt(ResString: PString; const Args: array of const); constructor CreateHelp(const Msg: string; AHelpContext: Longint); constructor CreateFmtHelp(const Msg: string; const Args: array of const; AHelpContext: Longint); constructor CreateResHelp(ResString: PString; AHelpContext: Longint); constructor CreateResFmtHelp(ResString: PString; const Args: array of const; AHelpContext: Longint); Function ToString : String; override; property HelpContext : longint read fhelpcontext write fhelpcontext; property Message : string read fmessage write fmessage; end;
Déclencher une Exception
raise exception.create('Cas non défini, à implementer...') ou formaté : raise exception.createFmt('Cas [%d] non défini, à implementer...',[varType(v)])
Try/Except : Capturer une Exception
try MaProcedureQuiDeclencheUnException; except on E:EOleException do Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); on E:Exception do Writeln(E.Classname, ':', E.Message); end;
Application.CaptureException
Apparement TApplication aurait une propertir CaptureException (public) pour gérer les exceptions…. a creuser.
procedure TApplication.RunLoop; begin repeat if CaptureExceptions then try // run with try..except HandleMessage; except HandleException(Self); end else HandleMessage; // run without try..except until Terminated; end;
Vous pourriez laisser un commentaire si vous étiez connecté.