Exception causes access violation



 DEVELOP > c-Plus-Plus > Exception causes access violation

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Toon Huysmans"
Date: 04 Nov 2003 06:14:45 AM
Object: 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("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.
.

User: "Ron Natalie"

Title: Re: Exception causes access violation 04 Nov 2003 08:04:22 AM
"Toon Huysmans" <tohu@ruca.ua.ac.be> wrote in message news:3fa79805.0@news.ruca.ua.ac.be...

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


  Page 1 of 1

1

 


Related Articles
Why moving a function from protected to public area in class causes error C2556
STL vector.push_back causes delete "object"
Calling dlsym()-ed function causes segfault
Tru64: Using stringstream to convert inbt/long to string causes application to crash
string ok as public causes core dump as public
loop thru a STL list causes an infinite loop
delete causes crash with character arrays
Creating object from the child of an abstract class causes to linkage errors
Likely causes of Unresolved external symbol in pure virtual function
Statically linked library causes segmentation violation upon C++ throw
Class throwing exceptions in aggregate static initializer causes abort() ...
What could normally causes the string to have no null terminated
C++: IFSTREAM causes problem
Possible causes for the 'delete ptr;' to core??
compiler unable to choose proper overloaded function (causes C2666)
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER