Use Debug.Assert to get Stack Trace information

Use Debug.Assert to get Stack Trace information

Part of the System.Diagnostic namespace, Debug.Assert() is used to
display the Call Strack Trace and it gives you three options – ‘Abort’,
‘Retry’ and ‘Ignore’. Basically when Debug.Assert() receives the
boolean parameter false a dialog box pops up giving you details with
Call Stack, and you can either end the program or continue.
One example of where you can use Debug.Assert() is when checking
if a file exists:


If the file doesn’t exist File.Exists() will return false, and (as mentioned earlier) when you pass this boolean value to Debug.Assert(), the Call Strack Trace dialog box pops up.
If you want you can test Debug.Assert() by directly passing the false parameter:


Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top