THRIFT-5004 Make exception implementations more consistent  [ci skip]
Client: Delphi
Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.pas b/lib/delphi/src/Thrift.pas
index e127380..abc0c1e 100644
--- a/lib/delphi/src/Thrift.pas
+++ b/lib/delphi/src/Thrift.pas
@@ -34,7 +34,7 @@
 
   TApplicationExceptionSpecializedClass = class of TApplicationExceptionSpecialized;
 
-  TApplicationException = class( TException)
+  TApplicationException = class abstract( TException)
   public
     type
 {$SCOPEDENUMS ON}
@@ -52,10 +52,10 @@
         UnsupportedClientType
       );
 {$SCOPEDENUMS OFF}
-  private
-    function GetType: TExceptionType;
   protected
     constructor HiddenCreate(const Msg: string);
+    class function GetType: TExceptionType;  virtual; abstract;
+    class function GetSpecializedExceptionType(AType: TExceptionType): TApplicationExceptionSpecializedClass;
   public
     // purposefully hide inherited constructor
     class function Create(const Msg: string): TApplicationException; overload; deprecated 'Use specialized TApplicationException types (or regenerate from IDL)';
@@ -63,7 +63,7 @@
     class function Create( AType: TExceptionType): TApplicationException; overload; deprecated 'Use specialized TApplicationException types (or regenerate from IDL)';
     class function Create( AType: TExceptionType; const msg: string): TApplicationException; overload; deprecated 'Use specialized TApplicationException types (or regenerate from IDL)';
 
-    class function GetSpecializedExceptionType(AType: TExceptionType): TApplicationExceptionSpecializedClass;
+    property Type_: TExceptionType read GetType;
 
     class function Read( const iprot: IProtocol): TApplicationException;
     procedure Write( const oprot: IProtocol );
@@ -75,38 +75,67 @@
     constructor Create(const Msg: string);
   end;
 
-  TApplicationExceptionUnknown = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionUnknownMethod = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionInvalidMessageType = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionWrongMethodName = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionBadSequenceID = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionMissingResult = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionInternalError = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionProtocolError = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionInvalidTransform = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionInvalidProtocol = class (TApplicationExceptionSpecialized);
-  TApplicationExceptionUnsupportedClientType = class (TApplicationExceptionSpecialized);
+  TApplicationExceptionUnknown = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionUnknownMethod = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionInvalidMessageType = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionWrongMethodName = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionBadSequenceID = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionMissingResult = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionInternalError = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionProtocolError = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionInvalidTransform = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionInvalidProtocol = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
+  TApplicationExceptionUnsupportedClientType = class (TApplicationExceptionSpecialized)
+  protected
+    class function GetType: TApplicationException.TExceptionType;  override;
+  end;
+
 
 
 implementation
 
 { TApplicationException }
 
-function TApplicationException.GetType: TExceptionType;
-begin
-  if Self is TApplicationExceptionUnknownMethod then Result := TExceptionType.UnknownMethod
-  else if Self is TApplicationExceptionInvalidMessageType then Result := TExceptionType.InvalidMessageType
-  else if Self is TApplicationExceptionWrongMethodName then Result := TExceptionType.WrongMethodName
-  else if Self is TApplicationExceptionBadSequenceID then Result := TExceptionType.BadSequenceID
-  else if Self is TApplicationExceptionMissingResult then Result := TExceptionType.MissingResult
-  else if Self is TApplicationExceptionInternalError then Result := TExceptionType.InternalError
-  else if Self is TApplicationExceptionProtocolError then Result := TExceptionType.ProtocolError
-  else if Self is TApplicationExceptionInvalidTransform then Result := TExceptionType.InvalidTransform
-  else if Self is TApplicationExceptionInvalidProtocol then Result := TExceptionType.InvalidProtocol
-  else if Self is TApplicationExceptionUnsupportedClientType then Result := TExceptionType.UnsupportedClientType
-  else Result := TExceptionType.Unknown;
-end;
-
 constructor TApplicationException.HiddenCreate(const Msg: string);
 begin
   inherited Create(Msg);
@@ -148,10 +177,12 @@
     TExceptionType.InvalidProtocol:       Result := TApplicationExceptionInvalidProtocol;
     TExceptionType.UnsupportedClientType: Result := TApplicationExceptionUnsupportedClientType;
   else
+    ASSERT( TExceptionType.Unknown = aType);
     Result := TApplicationExceptionUnknown;
   end;
 end;
 
+
 class function TApplicationException.Read( const iprot: IProtocol): TApplicationException;
 var
   field : TThriftField;
@@ -236,4 +267,62 @@
   inherited HiddenCreate(Msg);
 end;
 
+{ specialized TApplicationExceptions }
+
+class function TApplicationExceptionUnknownMethod.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.UnknownMethod;
+end;
+
+class function TApplicationExceptionInvalidMessageType.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.InvalidMessageType;
+end;
+
+class function TApplicationExceptionWrongMethodName.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.WrongMethodName;
+end;
+
+class function TApplicationExceptionBadSequenceID.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.BadSequenceID;
+end;
+
+class function TApplicationExceptionMissingResult.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.MissingResult;
+end;
+
+class function TApplicationExceptionInternalError.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.InternalError;
+end;
+
+class function TApplicationExceptionProtocolError.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.ProtocolError;
+end;
+
+class function TApplicationExceptionInvalidTransform.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.InvalidTransform;
+end;
+
+class function TApplicationExceptionInvalidProtocol.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.InvalidProtocol;
+end;
+
+class function TApplicationExceptionUnsupportedClientType.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.UnsupportedClientType;
+end;
+
+class function TApplicationExceptionUnknown.GetType : TApplicationException.TExceptionType;
+begin
+  result := TExceptionType.Unknown;
+end;
+
+
 end.