Why doesn't "checked" work for sub calls?

  • Thread starter Thread starter AliRezaGoogle
  • Start date Start date
A

AliRezaGoogle

Dear Members
Hi,
I have a question:
Why doesn't "checked" work for sub calls? For example consider the
following snippet of code:

checked
{
Overflower();
}

void Overflower()
{
int t=int.MaxValue;
t++;
}

Why Overflower doesn't throw overflow exception?
 
AliRezaGoogle said:
Dear Members
Hi,
I have a question:
Why doesn't "checked" work for sub calls?

A fairly complex path could be created if allowed.

Imagine something like this:

public static void Main()
{
checked
{
RunProgram();
}
}

Can you imagine the overhead with this? Ouch!
For example consider the
following snippet of code:

checked
{
Overflower();
}

void Overflower()
{
int t=int.MaxValue;
t++;
}

Why Overflower doesn't throw overflow exception?

Because it is not checked.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top