mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-14 11:09:41 +02:00
+ Added RTL error handling
This commit is contained in:
parent
630d8ea8d2
commit
3dadf35145
@ -54,9 +54,8 @@ interface
|
|||||||
fhelpcontext : longint;
|
fhelpcontext : longint;
|
||||||
public
|
public
|
||||||
constructor create(const msg : string);
|
constructor create(const msg : string);
|
||||||
//!! No array of const yet.
|
constructor createfmt(const msg : string; const args : array of const);
|
||||||
// constructor createfmt(const msg; const args : array of const);
|
constructor createres(ident : longint);
|
||||||
constructor createres(indent : longint);
|
|
||||||
{ !!!! }
|
{ !!!! }
|
||||||
property helpcontext : longint read fhelpcontext write fhelpcontext;
|
property helpcontext : longint read fhelpcontext write fhelpcontext;
|
||||||
property message : string read fmessage write fmessage;
|
property message : string read fmessage write fmessage;
|
||||||
@ -64,12 +63,29 @@ interface
|
|||||||
|
|
||||||
exceptclass = class of exception;
|
exceptclass = class of exception;
|
||||||
|
|
||||||
{ math. exceptions }
|
{ integer math exceptions }
|
||||||
einterror = class(exception);
|
EInterror = Class(Exception);
|
||||||
edivbyzero = class(einterror);
|
EDivByZero = Class(EIntError);
|
||||||
erangeerror = class(einterror);
|
ERangeError = Class(EIntError);
|
||||||
eintoverflow = class(einterror);
|
EIntOverflow = Class(EIntError);
|
||||||
ematherror = class(exception);
|
|
||||||
|
{ General math errors }
|
||||||
|
EMathError = Class(Exception);
|
||||||
|
EInvalidOp = Class(EMathError);
|
||||||
|
EZeroDivide = Class(EMathError);
|
||||||
|
EOverflow = Class(EMathError);
|
||||||
|
EUnderflow = Class(EMathError);
|
||||||
|
|
||||||
|
{ Run-time and I/O Errors }
|
||||||
|
EInOutError = class(Exception)
|
||||||
|
public
|
||||||
|
ErrorCode : Longint;
|
||||||
|
end;
|
||||||
|
EInvalidPointer = Class(Exception);
|
||||||
|
EOutOfMemory = Class(Exception);
|
||||||
|
|
||||||
|
econverterror = class(exception);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ Read date & Time function declarations }
|
{ Read date & Time function declarations }
|
||||||
@ -90,6 +106,18 @@ interface
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
{ Read message string definitions }
|
||||||
|
{
|
||||||
|
Add a language with IFDEF LANG_NAME
|
||||||
|
just befor the final ELSE. This way English will always be the default.
|
||||||
|
}
|
||||||
|
|
||||||
|
{$IFDEF LANG_GERMAN}
|
||||||
|
{$i strg.inc} // Does not exist yet !!
|
||||||
|
{$ELSE}
|
||||||
|
{$i stre.inc}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Read filename handling functions implementation }
|
{ Read filename handling functions implementation }
|
||||||
|
|
||||||
{$i fina.inc}
|
{$i fina.inc}
|
||||||
@ -113,15 +141,16 @@ interface
|
|||||||
{!!!!!}
|
{!!!!!}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
|
||||||
constructor exception.createfmt(const msg; const args : array of const);
|
constructor exception.createfmt(const msg : string; const args : array of const);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
|
fmessage:=Format(msg,args);
|
||||||
end;
|
end;
|
||||||
}
|
|
||||||
|
|
||||||
constructor exception.createres(indent : longint);
|
|
||||||
|
constructor exception.createres(ident : longint);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
inherited create;
|
inherited create;
|
||||||
@ -148,6 +177,39 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Var OutOfMemory : EOutOfMemory;
|
||||||
|
InValidPointer : EInvalidPointer;
|
||||||
|
|
||||||
|
|
||||||
|
Procedure RunErrorToExcept (ErrNo : Longint; Address : Pointer);
|
||||||
|
|
||||||
|
Var E : Exception;
|
||||||
|
S : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Case Errno of
|
||||||
|
1 : E:=OutOfMemory;
|
||||||
|
//!! ?? 2 is a 'file not found error' ??
|
||||||
|
2 : E:=InvalidPointer;
|
||||||
|
3,4,5,100,101,106 : { I/O errors }
|
||||||
|
begin
|
||||||
|
Case Errno of
|
||||||
|
3 : S:=SInvalidFileName;
|
||||||
|
4 : S:=STooManyOpenFiles;
|
||||||
|
5 : S:=SAccessDenied;
|
||||||
|
100 : S:=SEndOfFile;
|
||||||
|
101 : S:=SDiskFull;
|
||||||
|
106 : S:=SInvalidInput;
|
||||||
|
end;
|
||||||
|
E:=EinOutError.Create (S);
|
||||||
|
EInoutError(E).ErrorCode:=IOresult; // Clears InOutRes !!
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
E:=Exception.CreateFmt (SUnKnownRunTimeError,[Errno]);
|
||||||
|
end;
|
||||||
|
Raise E {at Address};
|
||||||
|
end;
|
||||||
|
|
||||||
Procedure InitExceptions;
|
Procedure InitExceptions;
|
||||||
{
|
{
|
||||||
Must install uncaught exception handler (ExceptProc)
|
Must install uncaught exception handler (ExceptProc)
|
||||||
@ -156,6 +218,10 @@ Procedure InitExceptions;
|
|||||||
}
|
}
|
||||||
begin
|
begin
|
||||||
ExceptProc:=@CatchUnhandledException;
|
ExceptProc:=@CatchUnhandledException;
|
||||||
|
// Create objects that may have problems when there is no memory.
|
||||||
|
OutOfMemory:=EOutOfMemory.Create(SOutOfMemory);
|
||||||
|
InvalidPointer:=EInvalidPointer.Create(SInvalidPointer);
|
||||||
|
ErrorProc:=@RunErrorToExcept;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -165,7 +231,10 @@ begin
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.10 1998-09-24 23:45:27 peter
|
Revision 1.11 1998-10-01 16:04:11 michael
|
||||||
|
+ Added RTL error handling
|
||||||
|
|
||||||
|
Revision 1.10 1998/09/24 23:45:27 peter
|
||||||
* updated for auto objpas loading
|
* updated for auto objpas loading
|
||||||
|
|
||||||
Revision 1.9 1998/09/24 16:13:49 michael
|
Revision 1.9 1998/09/24 16:13:49 michael
|
||||||
|
Loading…
Reference in New Issue
Block a user