In C# I can't throw an internal exception from the private method of a public class, even if I absolutely always catch it so it doesn't get exposed outside of the assembly... any workaround for this other than making the exception class public?
In C#, internal exceptions are designed to only be visible within the assembly where they are defined. However, since you cannot throw an internal exception from a private method of a public class, one workaround is to define a custom exception class that is visible within the assembly, but not outside of it.
Note: Check visibility at https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.internalsvisibletoattribute?view=net-7.0
Here's an example of how you can define an internal exception class and use it within a public class:
// Define an internal exception class within the assembly