cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

OTK - throwing exceptions - xthrow

FV
17-Peridot
17-Peridot

OTK - throwing exceptions - xthrow

Hi all,


Does anybody has an example of using OTK function xthrow. Curiously enough there are quite a number of examples of xcatch but nothing demonstrates an intended usage of xthrow.


TIA.


Happy New Year.


Feliks.


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
3 REPLIES 3
Eike_Hauptmann
15-Moonstone
(To:FV)

Hi Felix,


I think you can't create ProEXExceptions outside of action listeners.


You can catch ProE Exceptions with something like this :


try {
pfcSession_ptr session = pfcGetProESession();
session->ChangeDirectory(xrstring(xstring(curdir)));
} xcatchbegin
xcatchcip(defaultEx)
cout<<defaultex<<endl;<br/>xcatchend

Otherwise you can use the normal C++ way to throw excpetions like this:


try {
throw 20;
} catch (int e) {
cout << "An exception occurred. Exception Nr. " << e << '\n';
}

So I think you can mix it up (never tested) like this:

try {
} catch (int e) {
} xcatchbegin
xcatchend

it could work, but I'm not on my workstation at this time, so I can test it later :)

Happy New Year to you too,
Best regards,
Eike


FV
17-Peridot
17-Peridot
(To:FV)

Hi all,

Eike,

You are correct - we can use C++ 'native' throw functionality.
IMHO it defeats the purpouse of handling OTK specific errors.


Here is a code snippet from OTKAsyncXSimplemode.cxx

pfcSession_ptr ses = pfcGetProESession();
wses->RibbonDefinitionfileLoad("otkAsyncExamples.rbn");




pfcAsyncConnection_ptr connection = pfcAsyncConnection::GetActiveConnection();
}
xcatch (cipXException, ciperr)
cout << "cip exception caught: " << ciperr << endl;
}
{

}
{

}
catch(...) {

}

If we would use 'throw' in our own code then the only thing we could do is to use the later 'catch' statement.


If one would expand xcatchbegin macro defined in cipxobj.h :

catch (xthrowable *__exc__) \
xthrowable_ptr __exc__ptr__ ((xthrowable *) __exc__); \
if (0) {

then we could see that whatever is thrown by xthrow function is initialized into some kind of smart pointer ( inherits from xobject which looks very similar to boost shared pointer) and the original exception instance being released.

Then control over smart pointer is passed to a some kind of reflection via xcatch macro:

} else if (TYPE::isObjKindOf (__exc__ptr__)) { \
void xthrow (xthrowable_ptr value);

And there we are back to my question which was how to use xthrow function.

TIA.
Feliks.

In Reply to Eike Petersen:



Hi Felix,


I think you can't create ProEXExceptions outside of action listeners.


You can catch ProE Exceptions with something like this :


try {
pfcSession_ptr session = pfcGetProESession();
session->ChangeDirectory(xrstring(xstring(curdir)));
} xcatchbegin
xcatchcip(defaultEx)
cout<xcatchend< pre=">

Otherwise you can use the normal C++ way to throw excpetions like this:
<pre>try {
throw 20;
} catch (int e) {
cout << "An exception occurred. Exception Nr. " << e << '\n';
}

So I think you can mix it up (never tested) like this:

try {
} catch (int e) {
} xcatchbegin
xcatchend

it could work, but I'm not on my workstation at this time, so I can test it later :)

Happy New Year to you too,
Best regards,
Eike



FV
17-Peridot
17-Peridot
(To:FV)

Hi all,


Finally figured outhow to do it. There is pfcXInAMethod which inherits from xthrowable.


The syntax:
pfcXInAMethod::Throw("throwing function name","message");


HIH.


Feliks.

Announcements


Top Tags