Assert

  • Thread starter Thread starter Peter Morris [Droopy eyes software]
  • Start date Start date
P

Peter Morris [Droopy eyes software]

Hi all

For runtime errors I throw exceptions, and for coding errors I use
System.Diagnostics.Debug.Assert. When an assertion fails my app shows an
error message but then allows the user to continue whereas I would like the
app to terminate.

Should I use an exception instead (if so, which type?), if not then how do I
get Assert to terminate the app?

Thanks


Pete
 
Asserts are debug only developer only validation tools used to ensure
internal programs integrity. E.g. you're developing an internal function
which takes a none-null string.

You can add an assert to make sure your never call it with null by mistake.



Exceptions should be used for real failures. Which type of exception to use?
That depends on circumstances. Of example ArgumentException would be
appropriate for incorrect argument.

You can create your own exceptions as needed. Next, add exceptions handing
and terminate your applications gracefully if you get one.


--
Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Asserts are debug only developer only validation tools used to ensure
internal programs integrity. E.g. you're developing an internal function
which takes a none-null string.

That is exactly how I would like to use them. This is how I would expect my
development process to work.

1) If the error can occur due to runtime factors such as a missing file or
user input, use an exception.
2) If the error can only occur due to a programming error, use an Assert.

Once you have finished testing your app in Debug mode and are happy that no
Assert(false) conditions occur then rebuild the app in Release mode and code
for Assert statements are not compiled into the output, making the app run
faster.

I completely fail to see the point of Assert given the way it works in
dotnet.

1) They remain in the output even in Release mode.
2) Unhandled asserts (which should be unrecoverable errors) allow the user
to click "Continue" as if nothing had happened.


What use are they?


Pete
 
Back
Top