473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trace.Assert not working...

Hi,
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?
Thanks
--
Thanks
SCSharma
Aug 23 '05 #1
2 2473
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
Aug 23 '05 #2
Interesting, I am not sure where but somewhere i had read that when assertion
fails the program execution is stopped but after reading Jon's response i
checked C# documentation and could not verify my assumption. That forces me
to think why would i ever use assert statements(in release mode) if the
program is not going to stop excution when assertions fail.It would make
sense for code to exit when assertions failed.
--
Thanks
SCSharma
"Jon Skeet [C# MVP]" wrote:
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

Aug 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
6
by: milkyway | last post by:
Hello out there, When one gets an error, they can use fprintf (Stdout, "File %s Line %d\n", __FILE__, __LINE__); Is there a similar way where on can print out the stack trace? Any help,...
2
by: S. Han | last post by:
I use Trace.Assert() through out my app and it's such a great way to debug a program. My question is is there any way to redirect the assertion pop-up to the command line output in my console...
2
by: Verane | last post by:
Hi all, I am writing code in C# using visual studio .NET 2003. I use System.Diagnostics.Trace.Assert, and when I get an assertion at run time, I can see the call stack. But for each line of the...
5
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write ...
9
by: Joe Rattz | last post by:
I can't seem to get to trace.axd. I have turned tracing on in web.config. Here is how I currently have i configured: <trace enabled="true" requestLimit="10" pageOutput="false"...
1
by: AJ | last post by:
How can I use Trace.Assert method? It says that 'Assert' is not a member of 'System.Web.TraceContext'. Please help. Thanks.
2
by: scsharma | last post by:
Hi, 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...
2
by: news.microsoft.com | last post by:
Hi all. If I wanted to write something so that, when an exception was thrown, and the stack unwound, the stack trace was captured with the values of the parameters (instead of just the parameter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.