Changeset 259
- Timestamp:
- Jul 31, 2011, 8:00:28 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/CoolWeb/WebServer/UWebApp.pas
r256 r259 27 27 FOnInitialize: TNotifyEvent; 28 28 procedure DoRun; override; 29 function DumpExceptionCallStack(E: Exception): string; 29 30 procedure HTTPServerRequest(HandlerData: THTTPHandlerData); 30 31 public … … 32 33 HTTPServer: THTTPServer; 33 34 HTTPSessionStorageFile: THTTPSessionStorageFile; 35 LogException: Boolean; 36 procedure ShowException(E: Exception); override; 34 37 procedure RegisterPage(PageClass: TWebPageClass; out Reference; Path: string); 35 38 constructor Create(AOwner: TComponent); override; … … 56 59 end; 57 60 61 58 62 { TRegistredPageList } 59 63 … … 72 76 procedure TWebApp.DoRun; 73 77 begin 74 if Assigned(FOnInitialize) then FOnInitialize(Self); 75 HTTPServer.Run; 76 Terminate; 78 try 79 if Assigned(FOnInitialize) then FOnInitialize(Self); 80 HTTPServer.Run; 81 finally 82 Terminate; 83 end; 84 end; 85 86 function TWebApp.DumpExceptionCallStack(E: Exception): string; 87 var 88 I: Integer; 89 Frames: PPointer; 90 Report: string; 91 begin 92 Report := 'Program exception! ' + LineEnding + 93 'Stacktrace:' + LineEnding + LineEnding; 94 if E <> nil then begin 95 Report := Report + 'Exception class: ' + E.ClassName + LineEnding + 96 'Message: ' + E.Message + LineEnding; 97 end; 98 Report := Report + BackTraceStrFunc(ExceptAddr); 99 Frames := ExceptFrames; 100 for I := 0 to ExceptFrameCount - 1 do 101 Report := Report + LineEnding + BackTraceStrFunc(PointerArray(Frames)[I]); 102 Result := Report; 77 103 end; 78 104 … … 109 135 end; 110 136 137 procedure TWebApp.ShowException(E: Exception); 138 var 139 hstdout: ^Text; 140 begin 141 if not LogException then begin 142 hstdout := @stdout; 143 WriteLn(hstdout^, 'Content-type: text/html'); 144 WriteLn(hstdout^); 145 Writeln(hstdout^, 'An unhandled exception occurred: ' + E.Message + '<br>'); 146 WriteLn(hstdout^, StringReplace(DumpExceptionCallStack(E), LineEnding, '<br>', [rfReplaceAll])); 147 end else begin 148 hstdout := @stdout; 149 WriteLn(hstdout^, 'Content-type: text/html'); 150 WriteLn(hstdout^); 151 WriteLn(hstdout^, 'Error occured during page generation.'); 152 hstdout := @stderr; 153 Writeln(hstdout^, 'An unhandled exception occurred: ' + E.Message + '<br>'); 154 WriteLn(hstdout^, StringReplace(DumpExceptionCallStack(E), LineEnding, '<br>', [rfReplaceAll])); 155 end; 156 end; 157 111 158 constructor TWebApp.Create(AOwner: TComponent); 112 159 begin
Note:
See TracChangeset
for help on using the changeset viewer.