I can’t do this in C#:
catch (Exception exception)
{
var wrappedException = new TException(exception);
}
Getting error “cannot provide arguments when creating an instance of type parameter ‘TException’. Just wanted to check with the community to see if there is any way to do something like this?
The easiest (and best) method is to call
Activator.CreateInstanceyourself. This is what the C# compiler actually does, as thenew()constraint just ensures that the specified type has a parameterless constructor; callingnew TException()actually usesActivator.CreateInstanceto instantiate the type.Something like this would work: