I created a library with many utility functions to perform some tasks and placed it in it’s own DLL.
Throughout the methods in this library, i’ve placed Debug.Assert statements to verify the state of the application.
The problem is, when the Assert is firing (the condition is false), it presents the dialog, clicking “Abort” on it causes the entire application that uses this DLL to crash.
This poses 2 questions:
-
Can this be avoided? i’d expect this to throw an exception without exiting the application.
-
How come a DLL can cause the application that loads it to exit? isn’t this a security breach?
Thanks
If you want to have an exception thrown, why dont you just throw an exception?
Change
to
Assert will leave the application, assertion are here to protect you from coder’s mistake. If a function should never receive a null pointer, and if it does then it would be a mistake, then an assert would be the right tool.
If you want to express an exceptionnal situation, than the exception is the tool you are looking for