The only real-world construct I can see that comes into play when you are using
preprocessing directives (#if,#endif,#define) to include or exclude code based
on the condition of one or more symbols. Consider the following:
<code>
using System;
class App
{
static void Main(string[] args)
{
if( args.Length == 0 )
{
Console.WriteLine("in if");
//#if option1 || option2 || option3
try
{
#if option1
Console.WriteLine("option1 in if/try");
#endif
#if option2
Console.WriteLine("option2 in if/try");
#endif
#if option3
Console.WriteLine("option3 in if/try");
#endif
}
finally
{
#if option1
Console.WriteLine("option1 in if/finally");
#endif
#if option2
Console.WriteLine("option2 in if/finally");
#endif
#if option3
Console.WriteLine("option3 in if/finally");
#endif
}
//#endif
}
else
{
Console.WriteLine("in else");
}
}
}
</code>
With bug: >csc /optimize+ bug.cs
Without bug: >csc /optimize+ bug.cs /define:option1,option2
Uncomment the non-obvious
<code>
#if option1 || option2 || option3
#endif
</code>
around the whole try/finally you will not see the error.
The use of a catch also avoids the error:
<code>
using System;
class App
{
static void Main(string[] args)
{
if( args.Length == 0 )
{
Console.WriteLine("in if");
try
{
}
catch
{
}
finally
{
}
}
else
{
Console.WriteLine("in else");
}
}
}
</code>
Lawrence E. Smithmier, Jr.
MCP, MCAD
(919) 522-9738
[EMAIL PROTECTED]
Quoting "J. Merrill" <[EMAIL PROTECTED]>:
> Ouch. That's actually more serious than the original -- I would not have
> imagined anyone needing (or thinking) to write a "using" statement with an
> empty body. When would that be necessary (or even useful)?
>
> In this code, do you need both the TRY and FINALLY blocks to be empty to see
> the bug? That's also not a likely real-world construct, is it?
>
<snip>
>
>
> J. Merrill / Analytical Software Corp
>
> ===================================
> This list is hosted by DevelopMentor� http://www.develop.com
> NEW! ASP.NET courses you may be interested in:
>
> 2 Days of ASP.NET, 29 Sept 2003, in Redmond
> http://www.develop.com/courses/2daspdotnet
>
> Guerrilla ASP.NET, 13 Oct 2003, in Boston
> http://www.develop.com/courses/gaspdotnet
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>
===================================
This list is hosted by DevelopMentor� http://www.develop.com
NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com