CW 8.0 Mac OSX: can't catch mem exceptions?!?

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by fbertrand2 » Fri, 24 Oct 2003 00:30:58


Hi!
(and help!) it seems that for the life-o-me, I cannot catch memory
exceptions in CW 8.0 for Mac OSX. I am surely doing something wrong,
but the following code only results in the de *** showing a "access
fault exception" dialog box...

Thank you for any help on this!
Frank

try{
int *p=0;
*p=-1;
}
catch(...)
{
NeverReached();
}
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by Howard Hin » Fri, 24 Oct 2003 01:32:21

In article < XXXX@XXXXX.COM >,



C++ catch clauses only catch C++ exceptions. A C++ exception is a
different animal than an access fault exception.

-Howard

 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by fbertrand2 » Sat, 25 Oct 2003 04:11:18

I have tried using "signal" and sigsegv, to no avail. Would that be a
better solution?
ex: (does not work)
func()
{
signal(SIGSEGV,&handler);
int *y=0;
*y=-1;
}
void handler(int param)
{
...
}

Thank you for any info on the topic!

Frank
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by Howard Hin » Sat, 25 Oct 2003 04:33:47

In article < XXXX@XXXXX.COM >,



Sometimes C++ programmers use "smart pointers" to catch these kinds of
errors:

#include <stdexcept>

template <class T>
class SmartPointer
{
public:
explicit SmartPointer(T* p = 0) : p_(p) {}

T& operator*() const
{
if (!p_)
throw std::logic_error("SmartPointer: null dereference");
return *p_;
}

//...
private:
T* p_;
};

#include <iostream>

int main()
{
try
{
int i;
SmartPointer<int> p1(&i);
*p1 = 1;
std::cout << *p1 << " " << i << '\n';
SmartPointer<int> p2;
*p2 = -1;
std::cout << *p2 << " " << i << '\n';
}
catch (std::exception& e)
{
std::cerr << e.what() << '\n';
return 1;
}
catch (...)
{
std::cerr << "Unknown exception\n";
return 1;
}
}

But personally, "access fault exception" works better for me.

-Howard
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by Josef W. W » Sat, 25 Oct 2003 05:07:58

In article < XXXX@XXXXX.COM >,




With CW9 we moved to letting the system handle the signal stuff instead
of using the MSL version. The previous code most likely would succeed
with CW9.
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by fbertrand2 » Sun, 26 Oct 2003 00:25:44


Are you saying it's impossible to do in CW8?
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by Josef W. W » Sun, 26 Oct 2003 05:56:02

In article < XXXX@XXXXX.COM >,




If you use BSD C instead of MSL C, then it'd work with CW8. If you
modify your MSL C in CW8 to yank out the guts of MSL's signal mechanism,
it'd work too. If you want to use MSL C unmodified, you want CW9.
 
 
 

CW 8.0 Mac OSX: can't catch mem exceptions?!?

Post by fbertrand2 » Wed, 29 Oct 2003 00:58:39

Thank you for your answer, it is appreciated. So there is no way to
intervene in MSL's signal mechanism...
Ah well...