Operating System - OpenVMS
1753620 Members
6438 Online
108797 Solutions
New Discussion юеВ

Re: Questions about C++ exceptions and signals.

 
SOLVED
Go to solution
Maxy2
Advisor

Re: Questions about C++ exceptions and signals.

Boris:
I just wanted to point out that the compiler option /exception=implicit applies to Alpha only. The documentation seems to be saying that Itanium doesn't need it, not that Itanium doesn't support it.

Dennis:
I think the fact that you can't throw out of a signal handler is something different. My understanding is that C++ try-throw-catch is implemented using OpenVMS condition handlers, so throwing an exception from a condition handler is like signalling from a condition handler, which you can't do. This is just like in C++: if an exception is thrown, and another exception gets thrown (due to unwinding the stack, for example) before the catch block is reached, the program terminates.

Here's an example where you can see how the access violation leads to a violation of exception safety:


#include
#include
#include

class A
{
public:
A() { cout << "A()" << endl; };
~A() { cout << "~A()" << endl; };
};

int foo()
{
try {
A a;
int x = *(int*)0;
return x;
} catch (struct chf$signal_array &obj) {
cout << "Caught in foo:" << obj.chf$l_sig_name << endl;
}
return 0;
}

int main ()
{
try {
int i = foo();
} catch (struct chf$signal_array &obj) {
cout << "Caught in main:" << obj.chf$l_sig_name << endl;
}
return 0;
}

If you run this as is, you get the following:

A()
Caught in foo:12

This is bad. No call to ~A().

Now comment out the line "A a;".

The output changes to:

Caught in main:12
WW304289
Frequent Advisor

Re: Questions about C++ exceptions and signals.

"
I just wanted to point out that the compiler option /exception=implicit applies to Alpha only.
"

This is exactly my point. This option is not available on Itanium and without it, catching non-C++ exceptions in a C++ catch block is not guaranteed to work.

"
The documentation seems to be saying that Itanium doesn't need it, not that Itanium doesn't support it.
"

If this is how the documentation describes it, the documentation should be corrected. I suggest, you contact your HP customer support representative for the definitive answer.

"
Here's an example where you can see how the access violation leads to a violation of exception safety.
"

The C++ standard has no provisions about "exception safety" of non-C++ exceptions. You are relying on VMS extension which is not fully implemented on VMS Itanium.

Thanks,
-Boris
Dennis Handly
Acclaimed Contributor

Re: Questions about C++ exceptions and signals.

>I think the fact that you can't throw out of a signal handler is something different.

Of course it is directly related on HP-UX. The Standard says you can't do that and we have implemented the aC++ runtime to assume that's true.

>My understanding is that C++ try-throw-catch is implemented using OpenVMS condition handlers

On HP-UX, they don't exist. And if they did, it wouldn't help. I.e. we assume only calls need to handle EH activity, only throws cause exceptions. Not loads/stores or floating point operations.

>so throwing an exception from a condition handler is like signalling from a condition handler, which you can't do. This is just like in C++: if an exception is thrown, and another exception gets thrown

I guess I don't know what a condition handler is.