scsharma <sh******@noemail.nospam> wrote:
I am having trouble with following piece of code:
Trace.Assert(args.Length >=1,"Invalid Argument list. Statement Date is
mandatory input");
I expect the code to stop execution and exit when args.length >= 1
condition is not true. I am using C#.
But whats happening is that i see dialog box when this condition is not
true even if i am in release mode. If i remove defaultevenlistner then code
does not show the daialog box but at same time it does code does not exit.
Code continues past the assert statement. What am i missing?
No, Trace.Assert isn't guaranteed to throw exceptions - it depends on
what trace listeners are attached to it.
If you really want an exception to be thrown (which seems reasonably),
you should just do:
if (args.Length < 1)
{
throw new IllegalArgumentException
("Invalid Argument list. Statement Date is mandatory input");
}
Of course, you could always add your own TraceListener which throws an
exception, but then you won't get the same behaviour if TRACE isn't
defined.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too