summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Farrell <jfarrell@apache.org>2011-11-23 14:30:41 +0000
committerJake Farrell <jfarrell@apache.org>2011-11-23 14:30:41 +0000
commitac10256fccfcc9a31946c26777007a41d7766489 (patch)
tree9d110073cfef3829d84d1129cc8cc584066fcfd5
parenta6c031ad41716173007677dda5e244d7b1314a3d (diff)
downloadthrift-ac10256fccfcc9a31946c26777007a41d7766489.tar.gz
Thrift-1435: make TException.Message property conformant to the usual expectations
Client: delphi Patch: Jens Geyer Make delphi exceptions act like standard TException within other languages git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1205415 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--compiler/cpp/src/generate/t_delphi_generator.cc16
-rw-r--r--lib/delphi/src/Thrift.pas17
-rw-r--r--lib/delphi/test/TestServer.pas3
3 files changed, 24 insertions, 12 deletions
diff --git a/compiler/cpp/src/generate/t_delphi_generator.cc b/compiler/cpp/src/generate/t_delphi_generator.cc
index 9395457cd..a238f688c 100644
--- a/compiler/cpp/src/generate/t_delphi_generator.cc
+++ b/compiler/cpp/src/generate/t_delphi_generator.cc
@@ -81,7 +81,7 @@ class t_delphi_generator : public t_oop_generator
void generate_delphi_struct_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
void generate_delphi_struct_result_writer_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
- void generate_delphi_struct_tostring_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception);
+ void generate_delphi_struct_tostring_impl(ostream& out, std::string cls_prefix, t_struct* tstruct, bool is_exception, bool is_x_factory);
void add_delphi_uses_list( string unitname);
@@ -900,8 +900,8 @@ void t_delphi_generator::generate_delphi_struct_impl( ostream& out, string cls_p
} else {
generate_delphi_struct_writer_impl( out, cls_prefix, tstruct, is_exception);
}
- generate_delphi_struct_tostring_impl( out, cls_prefix, tstruct, is_exception);
}
+ generate_delphi_struct_tostring_impl( out, cls_prefix, tstruct, is_exception, is_x_factory);
if (is_exception && is_x_factory) {
generate_delphi_create_exception_impl( out, cls_prefix, tstruct, is_exception);
@@ -1039,10 +1039,8 @@ void t_delphi_generator::generate_delphi_struct_definition(ostream &out, t_struc
indent(out) << "constructor Create;" << endl;
indent(out) << "destructor Destroy; override;" << endl;
- if ((! is_exception) || is_x_factory) {
- out << endl;
- indent(out) << "function ToString: string; override;" << endl;
- }
+ out << endl;
+ indent(out) << "function ToString: string; override;" << endl;
if (is_exception && (! is_x_factory)) {
out << endl;
@@ -2337,6 +2335,8 @@ void t_delphi_generator::generate_delphi_create_exception_impl(ostream& out, str
indent_impl(out) << "end;" << endl;
}
+ indent_impl(out) << "Result.UpdateMessageProperty;" << endl;
+
indent_down_impl();
indent_impl(out) << "end;" << endl << endl;
}
@@ -2593,7 +2593,7 @@ void t_delphi_generator::generate_delphi_struct_writer_impl(ostream& out, string
}
-void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception) {
+void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out, string cls_prefix, t_struct* tstruct, bool is_exception, bool is_x_factory) {
const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
@@ -2601,7 +2601,7 @@ void t_delphi_generator::generate_delphi_struct_tostring_impl(ostream& out, stri
string cls_nm;
if (is_exception) {
- cls_nm = type_name(tstruct,true,false,true,true);
+ cls_nm = type_name(tstruct,true,(! is_x_factory),is_x_factory,true);
} else {
cls_nm = type_name(tstruct,true,false);
}
diff --git a/lib/delphi/src/Thrift.pas b/lib/delphi/src/Thrift.pas
index 50513d35d..dceb256c6 100644
--- a/lib/delphi/src/Thrift.pas
+++ b/lib/delphi/src/Thrift.pas
@@ -60,17 +60,26 @@ type
// base class for IDL-generated exceptions
TException = class( SysUtils.Exception)
public
- procedure Message; // hide inherited property to prevent accidental read/write
+ function Message : string; // hide inherited property: allow read, but prevent accidental writes
+ procedure UpdateMessageProperty; // update inherited message property with toString()
end;
implementation
{ TException }
-procedure TException.Message;
-// hide inherited property to prevent accidental read/write
+function TException.Message;
+// allow read (exception summary), but prevent accidental writes
+// read will return the exception summary
begin
- ASSERT( FALSE, 'Unexpected call to '+ClassName+'.message. Forgot the underscore?');
+ 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 }
diff --git a/lib/delphi/test/TestServer.pas b/lib/delphi/test/TestServer.pas
index ecaf80d60..26d49d2c5 100644
--- a/lib/delphi/test/TestServer.pas
+++ b/lib/delphi/test/TestServer.pas
@@ -115,6 +115,7 @@ begin
x := TXception.Create;
x.ErrorCode := 1001;
x.Message_ := 'This is an Xception';
+ x.UpdateMessageProperty;
raise x;
end;
end;
@@ -280,6 +281,7 @@ begin
x := TXception.Create;
x.ErrorCode := 1001;
x.Message_ := 'This is an Xception';
+ x.UpdateMessageProperty;
raise x;
end else
if ( arg0 = 'Xception2') then
@@ -288,6 +290,7 @@ begin
x2.ErrorCode := 2002;
x2.Struct_thing := TXtructImpl.Create;
x2.Struct_thing.String_thing := 'This is an Xception2';
+ x2.UpdateMessageProperty;
raise x2;
end;