THRIFT-4549 Thrift exceptions should derive from TException
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.Exception.pas b/lib/delphi/src/Thrift.Exception.pas
new file mode 100644
index 0000000..5d15c36
--- /dev/null
+++ b/lib/delphi/src/Thrift.Exception.pas
@@ -0,0 +1,62 @@
+(*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *)
+
+{$SCOPEDENUMS ON}
+
+unit Thrift.Exception;
+
+interface
+
+uses
+ Classes, SysUtils;
+
+type
+ // base class for all Thrift exceptions
+ TException = class( SysUtils.Exception)
+ public
+ function Message : string; // hide inherited property: allow read, but prevent accidental writes
+ procedure UpdateMessageProperty; // update inherited message property with toString()
+ end;
+
+
+
+
+implementation
+
+{ TException }
+
+function TException.Message;
+// allow read (exception summary), but prevent accidental writes
+// read will return the exception summary
+begin
+ result := Self.ToString;
+end;
+
+procedure TException.UpdateMessageProperty;
+// Update the inherited Message property to better conform to standard behaviour.
+// Nice benefit: The IDE is now able to show the exception message again.
+begin
+ inherited Message := Self.ToString; // produces a summary text
+end;
+
+
+
+
+end.
+
diff --git a/lib/delphi/src/Thrift.Protocol.pas b/lib/delphi/src/Thrift.Protocol.pas
index 24f6791..36509ca 100644
--- a/lib/delphi/src/Thrift.Protocol.pas
+++ b/lib/delphi/src/Thrift.Protocol.pas
@@ -27,6 +27,7 @@
Classes,
SysUtils,
Contnrs,
+ Thrift.Exception,
Thrift.Stream,
Thrift.Collections,
Thrift.Transport;
@@ -116,7 +117,7 @@
function Append(const Value: IThriftContainer): TStringBuilder; overload;
end;
- TProtocolException = class( Exception )
+ TProtocolException = class( TException)
public
const // TODO(jensg): change into enum
UNKNOWN = 0;
diff --git a/lib/delphi/src/Thrift.Transport.pas b/lib/delphi/src/Thrift.Transport.pas
index 4af65f9..997f406 100644
--- a/lib/delphi/src/Thrift.Transport.pas
+++ b/lib/delphi/src/Thrift.Transport.pas
@@ -39,6 +39,7 @@
{$ENDIF}
{$ENDIF}
Thrift.Collections,
+ Thrift.Exception,
Thrift.Utils,
Thrift.Stream;
@@ -79,7 +80,7 @@
procedure Flush; virtual;
end;
- TTransportException = class( Exception )
+ TTransportException = class( TException)
public
type
TExceptionType = (
diff --git a/lib/delphi/src/Thrift.pas b/lib/delphi/src/Thrift.pas
index 6eca3c9..ddd4c11 100644
--- a/lib/delphi/src/Thrift.pas
+++ b/lib/delphi/src/Thrift.pas
@@ -22,15 +22,19 @@
interface
uses
- SysUtils, Thrift.Protocol;
+ SysUtils,
+ Thrift.Exception,
+ Thrift.Protocol;
const
Version = '1.0.0-dev';
type
+ TException = Thrift.Exception.TException; // compatibility alias
+
TApplicationExceptionSpecializedClass = class of TApplicationExceptionSpecialized;
- TApplicationException = class( SysUtils.Exception )
+ TApplicationException = class( TException)
public
type
{$SCOPEDENUMS ON}
@@ -83,31 +87,9 @@
TApplicationExceptionInvalidProtocol = class (TApplicationExceptionSpecialized);
TApplicationExceptionUnsupportedClientType = class (TApplicationExceptionSpecialized);
- // base class for IDL-generated exceptions
- TException = class( SysUtils.Exception)
- public
- function Message : string; // hide inherited property: allow read, but prevent accidental writes
- procedure UpdateMessageProperty; // update inherited message property with toString()
- end;
implementation
-{ TException }
-
-function TException.Message;
-// allow read (exception summary), but prevent accidental writes
-// read will return the exception summary
-begin
- result := Self.ToString;
-end;
-
-procedure TException.UpdateMessageProperty;
-// Update the inherited Message property to better conform to standard behaviour.
-// Nice benefit: The IDE is now able to show the exception message again.
-begin
- inherited Message := Self.ToString; // produces a summary text
-end;
-
{ TApplicationException }
function TApplicationException.GetType: TExceptionType;