Jens Geyer | 606f1ef | 2018-04-09 23:09:41 +0200 | [diff] [blame] | 1 | (* |
| 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 | |
| 22 | unit Thrift.Exception; |
| 23 | |
| 24 | interface |
| 25 | |
| 26 | uses |
| 27 | Classes, SysUtils; |
| 28 | |
| 29 | type |
| 30 | // base class for all Thrift exceptions |
| 31 | TException = class( SysUtils.Exception) |
| 32 | public |
| 33 | function Message : string; // hide inherited property: allow read, but prevent accidental writes |
| 34 | procedure UpdateMessageProperty; // update inherited message property with toString() |
| 35 | end; |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | implementation |
| 41 | |
| 42 | { TException } |
| 43 | |
| 44 | function TException.Message; |
| 45 | // allow read (exception summary), but prevent accidental writes |
| 46 | // read will return the exception summary |
| 47 | begin |
| 48 | result := Self.ToString; |
| 49 | end; |
| 50 | |
| 51 | procedure TException.UpdateMessageProperty; |
| 52 | // Update the inherited Message property to better conform to standard behaviour. |
| 53 | // Nice benefit: The IDE is now able to show the exception message again. |
| 54 | begin |
| 55 | inherited Message := Self.ToString; // produces a summary text |
| 56 | end; |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | end. |
| 62 | |