Skip to content
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

Can we reduce the amount of custom DynamicProxy exception types? #518

Closed
stakx opened this issue Jun 15, 2020 · 4 comments · Fixed by #528
Closed

Can we reduce the amount of custom DynamicProxy exception types? #518

stakx opened this issue Jun 15, 2020 · 4 comments · Fixed by #528
Assignees

Comments

@stakx
Copy link
Member

stakx commented Jun 15, 2020

DynamicProxy currently defines four exception types:

  • GeneratorException
  • InvalidMixinConfigurationException
  • InvalidProxyConstructorArgumentsException
  • ProxyGenerationException

The uses of these exceptions can be roughly summarized as follows:

  • User code invokes DynamicProxy incorrectly. In many instances, a ArgumentException or InvalidOperationException could be thrown instead.
  • Something truly unexpected happens, e.g. because of a possible bug. In these few circumstances, it would seem proper to throw a custom exception type.

In none of these circumstances would user code profit from catching the exceptions thrown by DynamicProxy, so there's really no point in having distinct exception types.

I may have glossed over some details in my summary above, nevertheless I would suggest that we reduce the amount of custom exception types in DP by (1) using standard FCL exception types where appropriate, and (2) using a single ProxyGenerationException (or perhaps better, a new, more generally named DynamicProxyException) for truly exceptional situations.

(If we do that, we may get rid of GeneratorException and thus the Castle.DynamicProxy.Generators sub-namespace in the public API. See #517 for the full argument.)

@jonorossi
Copy link
Member

I definitely like the idea of using FCL exceptions (e.g. ArgumentException and InvalidOperationException) instead of a custom exception because you provide your own message anyway. Why we've got GeneratorException and ProxyGenerationException it strange.

I recall DP also throws TargetException and TargetInvocationException during execution of proxies if things blow up (but they might be captured as inner exceptions), so agree there is no need for multiple custom exceptions.

If you put together a PR probably using a single DynamicProxyException and FCL exceptions where it makes sense I'm happy to review it.

@jonorossi
Copy link
Member

The pull requests were all great, I'm happy with all the changes. Thrown exceptions definitely follow a clean pattern now.

@stakx
Copy link
Member Author

stakx commented Jun 29, 2020

@jonorossi, I'm glad you were happy with the changes. I couldn't quite shake the feeling that those PRs were a bit messy, but that was perhaps unavoidable, given the many case-by-case decisions necessary. It feels good to have those exceptions out of the way now!

@jonorossi
Copy link
Member

I couldn't quite shake the feeling that those PRs were a bit messy, but that was perhaps unavoidable, given the many case-by-case decisions necessary.

I didn't feel that way. The commit messages made it easy to follow your thought process.

iamdmitrij added a commit to iamdmitrij/Tethos that referenced this issue May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants