-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Marshalling: Exception subclasses #205
Comments
While the .NET exception message and stack trace are propagated to the JS Would you expect a subclass of JS |
Due to the weak-type nature of Javascript, and the existence of popular tools trying to minimise Javascript code size, I think having additional properties would be more robust. And I guess that is also easier to implement. |
But that also depends on the ambition of this project. If it is about "calling .NET from Node.js without noticing it", probably 1:1 mapping between Exception/Error types would be better. Personally I feel too good usually can't be true. Personally I am quite happy to be aware that I am writing the glue code to connect .NET and Node.js. |
I think that would be great if it could be a 1:1 Exception/Error in the generated code, because it would match the logic in Task/Promise and other "native" mappings. For instance, a class FormatError extends Error {
...
} That way, one could use it like this: try {
...
}
catch (error) {
if (error instanceof FormatError) { // IMHO, this is the best way to work with errors in JavaScript (seems more "strict" to language semantics, even JS being a very dynamic language)
...
}
} With custom properties, seems that the library would be using a "workaround" to allow error identification, which I don't think is a great way to do it (although it seems to be easier for now). |
class FormatError extends Error {
...
} Something like this should be possible (though definitely more work). Another advantage is it would allow JS to access any other properties or methods on the .NET Exception subclass, which could be very important in certain error-handling scenarios. I'm adding this feature to the roadmap. |
For example, if in .NET I have this:
then in Node, can I know that the Error is caused by "FormatException"?
It seems this feature is missing so that the only way is to check the "message" property of the Error object?
The text was updated successfully, but these errors were encountered: