|
|
|
|||||
|
Slice: Defining Exception with Message member
I defined an exception like this:
exception WSAAError { string Message; }; This generates non-compilable code in C# (and probably VB as well), as the Slice compiler tries to assign to the pre-existing read-only Message property in the .NET Exception class. Karl |
|
|||||
|
It would be cool if - in case of a name clash - the Slice code generator could simply take advantage of existing members (even if assignment has to be done in the constructor). Some kind of annotation might be useful there.
In my case this would mean that defining a Message member would simply expose an existing property of the built-in Exception class. Its probably not as simple as it sounds, as you can't define a read-only member in Slice (unless through annotations?). Karl |
|
||||||
|
I don't think what you suggest is feasible, mainly because the clash can happen with both operations and properties and because properties can be read-only.
Pragmatically, the only option is to mangle such exception members. For example, a "Message" exception member would be mapped as "ice_Message" or similar. Cheers, Michi. |
|
|||||
|
Quote:
It's just inconvenient that Slice exceptions always have an empty message, as this is probably the most used member. Karl |
|
||||||
|
The reason it is this way is the one-shot constructor for exceptions. If we were to permit the Message member of the base exception to be used, we couldn't have one-shot constructors for exceptions with string members because the constructor would become ambigous. (Which member would be initialized, the member in the base or the member in the exception itself.)
Also, using the Message member of the base exception is probably not such a good idea because it won't work across languages (because, for example, for C++, there is no such base exception). If you really want a message member, define it in Slice in the exception; that way, the member is available across all languages, and is available even if the exception is marshaled over the wire. Cheers, Michi. |
|
|||||
|
Quote:
Quote:
Karl |
|
||||||
|
Quote:
Also, using a virtual property has the problem that, if an exception is passed as its base type, and the receiver uses the property, what it gets is the property of the base class, not the overridden implementation in the derived class. This can lead to rather surprising behavior. I think the simple and pragmatic solution is to mangle the name of a Slice exception member if that name collides with a member of ApplicationException and its bases. But, before dismissing this out of hand, I'd like to at least consider it. I think I know what you mean, but could you post an example of what the generated code would look like, at least in outline? Cheers, Michi. |
|
|||||
|
Quote:
For example, Code:
exception PBSError {
["dotNet:->Message(property, virtual, readonly)"]
string Reason;
};
Quote:
Quote:
Code:
public override string Message {
get {
return Reason;
}
}
Anyway, as a "funny" side note: the current project I am working on - the first where we will be using ICE in production - has the purpose of wrapping a vendor's web services, since they turned out not to be as inter-operable as one would expect. Karl |
|
||||||
|
Quote:
There are also issues relating to the type system. For example, how should the mapping deal with an exception that defines a Message member, but with different type? Code:
exception E
{
int Message;
};
Code:
public class E : global::System.ApplicationException
{
public new int Message;
}
Quote:
Quote:
Quote:
Cheers, Michi. |
|
|||||
|
Quote:
Quote:
As I observed, you are already re-naming Slice members with name clashes (although there seems to be a bug in the code generated for initDM__). So, as far as my suggestion is concerned, it can stay as it is (without the bug, of course), and the mapping should still work, since it is nothing else but an assignment or override for a pre-existing member. Quote:
Quote:
Quote:
I am actually surprised that no-one has laughed me out of the building yet for suggesting ICE, but I guess at the end of the day a working solution wins... Karl |
|
|||||
|
Quote:
Still, probably better to emit an error/warning on slice2cs. Cheers,
__________________
-- Andrew Bell National Resources Inventory Center for Survey Statistics & Methodology Iowa State University andrew.bell.ia@gmail.com |
|
||||||
|
Quote:
Quote:
So, we'd have to add some renaming mechanism via metadata that would allow the Slice member to be renamed to something else. But I don't like the complexity of this. I think we need to keep in the mind the scope of the problem we are trying to solve: name clashes such as the one you found are rare in practice. In the few cases where a name clash become an issue, identifier mangling is a simple and effective way of dealing with the clash. Quote:
Quote:
Cheers, Michi. |