Reputation: 16389
I am writing a license module (DLL) for multiple applications. This DLL will be used in applications by adding reference. One of the requirement (pass case) for this DLL is that, if license validation fails, calling application should terminate/crash. It should not gracefully shutdown; it must crash. I do not want to show message, write log etc.
DLL and applications (using this DLL) are written in DotNet 4.
Quick solution I can think of is to throw exception instead of returning value from method. But, the exception could be caught by application and purpose will not be fully served.
Workaround for this is to declare custom exception as internal
in my DLL. But, this also could be bypassed by catching Exception
class.
One dirty alternative I can think of is to write a code (endless recursion or something) that will throw StackOverflowException
. But I am looking for something better.
Is there any way to throw custom non-catchable exception?
Ref1 and Ref2 discuss about in built DotNet non-catchable exception. My question is about custom non-catchable exceptions.
Upvotes: 0
Views: 167
Reputation: 430
Environment.FailFast
is the way to go, nothing can then prevent your application from shutting down.
Keep in mind that C# libraries can be easily changed and recompiled, so you might also want to look into using obfuscators as well.
Upvotes: 1