From 1f40ff23627382335efd52c9aeaebae3af6e9524 Mon Sep 17 00:00:00 2001 From: marco Date: Sun, 15 Jan 2012 11:54:12 +0000 Subject: [PATCH] * overloaded version of raiselastoserror that allows custom errorcodes to be raised, patch by Cytax, Mantis #21092 git-svn-id: trunk@20084 - --- rtl/objpas/sysutils/osutilsh.inc | 3 ++- rtl/objpas/sysutils/sysutils.inc | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/rtl/objpas/sysutils/osutilsh.inc b/rtl/objpas/sysutils/osutilsh.inc index b1d7ab634b..1bf283c9f5 100644 --- a/rtl/objpas/sysutils/osutilsh.inc +++ b/rtl/objpas/sysutils/osutilsh.inc @@ -19,7 +19,8 @@ Type TExecuteFlags = Set of ( ExecInheritsHandles); {$ifdef HAS_OSERROR} Function GetLastOSError : Integer; {$endif} -Procedure RaiseLastOSError; +Procedure RaiseLastOSError;overload; +Procedure RaiseLastOSError(LastError: Integer);overload; Function GetEnvironmentVariable(Const EnvVar : String) : String; Function GetEnvironmentVariableCount : Integer; Function GetEnvironmentString(Index : Integer) : String; diff --git a/rtl/objpas/sysutils/sysutils.inc b/rtl/objpas/sysutils/sysutils.inc index 7ef6342590..186ccc72aa 100644 --- a/rtl/objpas/sysutils/sysutils.inc +++ b/rtl/objpas/sysutils/sysutils.inc @@ -408,27 +408,34 @@ begin end; {$IFDEF HAS_OSERROR} -Procedure RaiseLastOSError; - -var - ECode: Cardinal; - E : EOSError; - +Procedure RaiseLastOSError;overload; begin - ECode := GetLastOSError; - If (ECode<>0) then - E:=EOSError.CreateFmt(SOSError, [ECode, SysErrorMessage(ECode)]) + RaiseLastOSError(GetLastOSError); +end; + +Procedure RaiseLastOSError(LastError: Integer);overload; +var + E : EOSError; +begin + If (LastError<>0) then + E:=EOSError.CreateFmt(SOSError, [LastError, SysErrorMessage(LastError)]) else E:=EOSError.Create(SUnkOSError); - E.ErrorCode:=ECode; + E.ErrorCode:=LastError; Raise E; end; -{$else} -Procedure RaiseLastOSError; +{$else} +Procedure RaiseLastOSError;overload; begin Raise Exception.Create('RaiseLastOSError not implemented on this platform.'); end; + +Procedure RaiseLastOSError(LastError: Integer);overload; +begin + RaiseLastOSError; +end; + {$endif} Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer); Var