blob: 88b1cfe03e71173955a8329b472e8a776c2a9ac3 [file] [log] [blame]
Jens Geyer606f1ef2018-04-09 23:09:41 +02001(*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19
20{$SCOPEDENUMS ON}
21
22unit Thrift.Exception;
23
24interface
25
26uses
27 Classes, SysUtils;
28
29type
30 // base class for all Thrift exceptions
31 TException = class( SysUtils.Exception)
Jens Geyere7808552019-12-04 21:24:08 +010032 strict private
33 function GetMessageText : string;
Jens Geyer606f1ef2018-04-09 23:09:41 +020034 public
35 function Message : string; // hide inherited property: allow read, but prevent accidental writes
36 procedure UpdateMessageProperty; // update inherited message property with toString()
37 end;
38
39
40
41
42implementation
43
44{ TException }
45
46function TException.Message;
47// allow read (exception summary), but prevent accidental writes
48// read will return the exception summary
49begin
Jens Geyere7808552019-12-04 21:24:08 +010050 result := Self.GetMessageText;
Jens Geyer606f1ef2018-04-09 23:09:41 +020051end;
52
Jens Geyere7808552019-12-04 21:24:08 +010053
Jens Geyer606f1ef2018-04-09 23:09:41 +020054procedure TException.UpdateMessageProperty;
55// Update the inherited Message property to better conform to standard behaviour.
56// Nice benefit: The IDE is now able to show the exception message again.
57begin
Jens Geyere7808552019-12-04 21:24:08 +010058 inherited Message := Self.GetMessageText;
Jens Geyer606f1ef2018-04-09 23:09:41 +020059end;
60
61
Jens Geyere7808552019-12-04 21:24:08 +010062function TException.GetMessageText : string;
63// produces a summary text
64begin
65 result := Self.ToString;
66 if (result <> '') and (result[1] = '(')
67 then result := Copy(result,2,Length(result)-2);
68end;
Jens Geyer606f1ef2018-04-09 23:09:41 +020069
70
71end.
72