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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AliRezaGoogle

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

    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?
  • Cowboy \(Gregory A. Beamer\)

    #2
    Re: Why doesn't "checked&q uot; work for sub calls?


    "AliRezaGoo gle" <asemoonya@yaho o.comwrote in message
    news:0f81ee5c-3a77-4d18-af8e-2b25e88048a0@x3 5g2000hsb.googl egroups.com...
    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


    or just read it:


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

    Comment

    Working...