3 This file is part of the Free Pascal run time library.
4 Copyright (c) 1999-2000 by Florian Klaempfl
5 member of the Free Pascal development team
7 See the file COPYING.FPC, included in this distribution,
8 for details about the copyright.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 **********************************************************************}
16 { Read message string definitions }
18 Add a language with IFDEF LANG_NAME
19 just befor the final ELSE. This way English will always be the default.
23 {$i strg.inc} // Does not exist yet !!
28 { Read filename handling functions implementation }
31 { Read String Handling functions implementation }
34 { Read date & Time function implementations }
37 { Read pchar handling functions implementation }
41 constructor Exception.Create(const msg : string);
49 constructor Exception.CreateFmt(const msg : string; const args : array of const);
53 fmessage:=Format(msg,args);
57 constructor Exception.CreateRes(ResString: PString);
65 constructor Exception.CreateResFmt(ResString: PString; const Args: array of const);
69 fmessage:=Format(ResString^,args);
73 constructor Exception.CreateHelp(const Msg: string; AHelpContext: Integer);
78 fhelpcontext:=AHelpContext;
82 constructor Exception.CreateFmtHelp(const Msg: string; const Args: array of const;
83 AHelpContext: Integer);
87 fmessage:=Format(Msg,args);
88 fhelpcontext:=AHelpContext;
92 constructor Exception.CreateResHelp(ResString: PString; AHelpContext: Integer);
97 fhelpcontext:=AHelpContext;
101 constructor Exception.CreateResFmtHelp(ResString: PString; const Args: array of const;
102 AHelpContext: Integer);
106 fmessage:=Format(ResString^,args);
107 fhelpcontext:=AHelpContext;
113 {$define STACKCHECK_WAS_ON}
116 Procedure CatchUnhandledException (Obj : TObject; Addr,Frame: Pointer);
120 Writeln(stdout,'An unhandled exception occurred at 0x',HexStr(Longint(Addr),8),' :');
121 if Obj is exception then
123 Message:=Exception(Obj).Message;
124 Writeln(stdout,Message);
127 Writeln(stdout,'Exception object ',Obj.ClassName,' is not of class Exception.');
128 { to get a nice symify }
129 Writeln(stdout,BackTraceStrFunc(Longint(Addr)));
130 Dump_Stack(stdout,longint(frame));
136 Var OutOfMemory : EOutOfMemory;
137 InValidPointer : EInvalidPointer;
140 Procedure RunErrorToExcept (ErrNo : Longint; Address,Frame : Pointer);
147 1,203 : E:=OutOfMemory;
148 204 : E:=InvalidPointer;
149 2,3,4,5,6,100,101,102,103,105,106 : { I/O errors }
152 2 : S:=SFileNotFound;
153 3 : S:=SInvalidFileName;
154 4 : S:=STooManyOpenFiles;
155 5 : S:=SAccessDenied;
156 6 : S:=SInvalidFileHandle;
157 15 : S:=SInvalidDrive;
160 102 : S:=SFileNotAssigned;
161 103 : S:=SFileNotOpen;
162 104 : S:=SFileNotOpenForInput;
163 105 : S:=SFileNotOpenForOutput;
164 106 : S:=SInvalidInput;
166 E:=EinOutError.Create (S);
167 EInoutError(E).ErrorCode:=IOresult; // Clears InOutRes !!
169 // We don't set abstracterrorhandler, but we do it here.
170 // Unless the use sets another handler we'll get here anyway...
171 200 : E:=EDivByZero.Create(SDivByZero);
172 201 : E:=ERangeError.Create(SRangeError);
173 205 : E:=EOverflow.Create(SOverflow);
174 206 : E:=EOverflow.Create(SUnderflow);
175 207 : E:=EInvalidOp.Create(SInvalidOp);
176 211 : E:=EAbstractError.Create(SAbstractError);
177 215 : E:=EIntOverflow.Create(SIntOverflow);
178 216 : E:=EAccessViolation.Create(SAccessViolation);
179 219 : E:=EInvalidCast.Create(SInvalidCast);
180 227 : E:=EAssertionFailed.Create(SAssertionFailed);
182 E:=Exception.CreateFmt (SUnKnownRunTimeError,[Errno]);
184 Raise E at longint(Address){$ifdef ENHANCEDRAISE},longint(Frame){$endif};
188 Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo,TheAddr : Longint);
196 Raise EAssertionFailed.Createfmt(SAssertError,[S,Fn,LineNo]); // at Pointer(theAddr);
199 {$ifdef STACKCHECK_WAS_ON}
203 Procedure InitExceptions;
205 Must install uncaught exception handler (ExceptProc)
206 and install exceptions for system exceptions or signals.
207 (e.g: SIGSEGV -> ESegFault or so.)
210 ExceptProc:=@CatchUnhandledException;
211 // Create objects that may have problems when there is no memory.
212 OutOfMemory:=EOutOfMemory.Create(SOutOfMemory);
213 InvalidPointer:=EInvalidPointer.Create(SInvalidPointer);
214 AssertErrorProc:=@AssertErrorHandler;
215 ErrorProc:=@RunErrorToExcept;
216 OnShowException:=Nil;
219 { Exception handling routines }
221 function ExceptObject: TObject;
224 If RaiseList=Nil then
227 Result:=RaiseList^.FObject;
230 function ExceptAddr: Pointer;
233 If RaiseList=Nil then
236 Result:=RaiseList^.Addr;
239 function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
240 Buffer: PChar; Size: Integer): Integer;
247 S:=Format(SExceptionErrorMessage,[ExceptObject.ClassName,ExceptAddr]);
248 If ExceptObject is Exception then
249 S:=Format('%s:'#10'%s',[S,Exception(ExceptObject).Message]);
258 Move(S[1],Buffer^,Len);
262 procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
264 // use shortstring. On exception, the heap may be corrupt.
270 SetLength(Buf,ExceptionErrorMessage(ExceptObject,ExceptAddr,@Buf[1],255));
274 If Assigned(OnShowException) Then
275 OnShowException (Buf);
281 Raise EAbort.Create(SAbortError) at Get_Caller_addr(Get_Frame)
284 procedure OutOfMemoryError;
292 Revision 1.1 2002/02/19 08:25:47 sasu
295 Revision 1.1.2.1 2000/08/20 15:07:37 peter
296 * sysutils.pp moved into target specific directory and merged
297 disk.inc and filutil.inc in it