Exception causes access violation

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

    Exception causes access violation

    Hi,

    I have a mind boggling error in VC++ .NET.

    An exception THException is being thrown, but it seems to cause an
    accessviolation , but the code is so simple that I cant figure out where the
    av comes from.


    MyMesh::Point cog()
    {
    if (fCount != 0)
    return fCoG/fCount;
    else
    throw THException("Th ere were no vertices to average...");
    <--- this gets thrown
    }


    class THException
    {
    public:
    THException(str ing msg){fMsg = msg;}
    string getMessage(){re turn fMsg;}
    protected:
    private:
    string fMsg;
    };


    try
    {
    ...
    mesh.cog()
    ...
    }
    catch(THExcepti on e)
    {
    cerr << "EXCEPTION: " << e.getMessage() << endl;
    exit(1);
    }
    catch(...)
    {
    cerr << "EXCEPTION: " << "Unknown Exception caught..." << endl;
    exit(1);
    }


    OUTPUT:
    First-chance exception at 0x77e73887 in SphericalParame terization.exe:
    Microsoft C++ exception: THException @ 0x0012f9d8.
    First-chance exception at 0x004f1bbc in SphericalParame terization.exe:
    0xC0000005: Access violation reading location 0xcdcdcddd.


  • Ron Natalie

    #2
    Re: Exception causes access violation


    "Toon Huysmans" <tohu@ruca.ua.a c.be> wrote in message news:3fa79805.0 @news.ruca.ua.a c.be...[color=blue]
    > Hi,
    >
    > I have a mind boggling error in VC++ .NET.[/color]

    Try this in micrsoft.public .vc.language. It looks fine from a C++ point of
    view (provided all those spurious copies of string don't throw).

    CDCDCDCD is the debug mode "fill" pattern for uninitialized memory.
    Are you sure the compile options you have specified allow exceptions?
    I don't know about .NET, but VC6 you had to specifically enable exception
    handling (and even then there were some bugs in it).
    [color=blue]
    > class THException
    > {
    > public:
    > THException(str ing msg){fMsg = msg;}[/color]

    How aboiut
    THException(con st string& msg) : fMsg(msg) { }
    [color=blue]
    > catch(THExcepti on e)[/color]

    If you ever derive from THException, would be better to catch by reference here.



    Comment

    Working...