I am using one function from native .dll in C# code and sometimes the following assert is calling:
#include <assert.h>
...
assert(e > 0.0);
But I can not catch it in my .NET application (it's just crashing). How can I handle this?
I am using one function from native .dll in C# code and sometimes the following assert is calling:
#include <assert.h>
...
assert(e > 0.0);
But I can not catch it in my .NET application (it's just crashing). How can I handle this?
At least by reading the Wiki:
When executed, if the expression is false (that is, compares equal to 0), assert() writes information about the call that failed on stderr and then calls abort().
And the MSDN
Evaluates an expression and, when the result is false, prints a diagnostic message and aborts the program.
so no exception... an error message and the program dies. Nothing to catch here :-)
Then we could talk about the difference in parameters handling between C and C#... In C you kill the program with an assert
, in C# you throw a catcheable exception (ArgumentException
)... Different methodologies :-)
Now, how to handle it? Don't cause assert
to fail is a good method :-) assert
are terminal errors (because even in C they can't be handled), so they shouldn't happen.