Exception causes access violation

Discussion in 'C++' started by Toon Huysmans, Nov 4, 2003.

  1. 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("There were no vertices to average...");
    <--- this gets thrown
    }


    class THException
    {
    public:
    THException(string msg){fMsg = msg;}
    string getMessage(){return fMsg;}
    protected:
    private:
    string fMsg;
    };


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


    OUTPUT:
    First-chance exception at 0x77e73887 in SphericalParameterization.exe:
    Microsoft C++ exception: THException @ 0x0012f9d8.
    First-chance exception at 0x004f1bbc in SphericalParameterization.exe:
    0xC0000005: Access violation reading location 0xcdcdcddd.
    Toon Huysmans, Nov 4, 2003
    #1
    1. Advertising

  2. Toon Huysmans

    Ron Natalie Guest

    "Toon Huysmans" <> wrote in message news:...
    > Hi,
    >
    > I have a mind boggling error in VC++ .NET.


    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).

    > class THException
    > {
    > public:
    > THException(string msg){fMsg = msg;}


    How aboiut
    THException(const string& msg) : fMsg(msg) { }

    > catch(THException e)


    If you ever derive from THException, would be better to catch by reference here.
    Ron Natalie, Nov 4, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. batista
    Replies:
    4
    Views:
    548
    Greg Comeau
    Nov 8, 2005
  2. Replies:
    2
    Views:
    1,160
  3. Sparky
    Replies:
    3
    Views:
    2,439
    Sparky
    Aug 4, 2009
  4. CS Student
    Replies:
    3
    Views:
    8,034
    Shao Miller
    Jun 17, 2011
  5. Alex
    Replies:
    7
    Views:
    113
Loading...

Share This Page