Welcome! Log In Create A New Profile


Ass 1 Q3.2 - Can't "catch" error code

Posted by lionelzone 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Ass 1 Q3.2 - Can't "catch" error code
March 30, 2006 06:23PM
In my currency_impl.cc file I have converted the fromCode and toCode to string. I then test for a valid string (i.e. ZAR, GWP or USD) using if statements. If the string is invalid I "throw()" the invalid string.

In the client.cc file I "try" the execute the convertor program and if it is invalid I catch the error string using "catch (string unknownCode)".

Everything compiles fine and when I use valid codes works 100%. But when I use an invalid code I get the following error message on the server command window:


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Does anyone know why I would be getting this message and not the error message I specified, namely:
cerr << "Unknown currency code: " << unknownCode << endl;

Any help will be greatly appreciated

Re: Ass 1 Q3.2 - Can't "catch" error code
March 31, 2006 08:48AM
I think you are being foiled by the type safety of C++ (and corba idl). The exception which you throw is not of type string but of type unknownCode.

What your client should be catching is:

catch (Currency::Convertor::unknownCode &e)

assuming your interface is defined inside the Currency module. Otherwise you should catch

catch (Convertor::unknownCode &e)

Re: Ass 1 Q3.2 - Can't "catch" error code
March 31, 2006 10:31AM
It still does the same thing. I obviously don't want to display all my code here but I think I can show you the following:

My currency_impl.cc has the following procedure header:

Convertor_impl::convert( CORBA::double amount, const char* fromCode, const char* toCode )

So from this you can see that I have created this within the a currency module.

Within this procedure I have converted char fromCode to string fCode and done the same for toCode and tCode. (This just makes the if else statements easier to understand.)

Once I have tested the input currency codes I have the following code:

// If none of the above is true then there is an invalid currency code
else if ((fCode == "ZAR"winking smiley || (fCode == "BWP"winking smiley || (fCode == "USD"winking smiley) {
else {

Since I have specified the throw type in the header, I am right in assuming that tCode and fCode will be thrown as type unknownCode?

I then use the catch code you specified above (which I had tried previously) in the client.cc code.

But I still get this error message about the application requesting the run-time to terminate unusually.

I don't know if it makes a difference, but I am running the application within a DOS box on a machine running Windows XP Professional.

P.S. I knew I shouldn't have taken that year break from c++ smile


Re: Ass 1 Q3.2 - Can't "catch" error code
March 31, 2006 11:08AM
This is probably quite complicated, but from what I can see you are throwing something of type std::string in your server convert() method. This is not in any way related to CORBA::Exception so it will not be marshalled and sent through to the client. It is simply going to crash your server as you (probably) have no anticipatory catch clause to catch a std::string in your server code.

You need to construct an object of type unknownCode using your std::string (or char*) as a parameter to the constructor, then throw that.

A further thought:
Once you have ironed out your issues relating to the above think about the situation where you have potentially 100's of valid currency codes to consider. Your if .. then .. else approach will not scale well. Ideally you need some form of lookup table. The stl std::map can work very well for this.

Hope this helps.
Re: Ass 1 Q3.2 - Can't "catch" error code
March 31, 2006 01:49PM
Thanks for all the help. At least my program is not bombing any longer. But I am still not getting the incorrect country code.

Now I get the following on the client side:
Unknown currency code: IDL:Currency/Convertor/unknownCode:1.0

I assign the unknownCode as follows:

Currency::Convertor::unknownCode e(toCode);

This seems to compile find, but if I put in the following code:

cout << e << " " << toCode << " " << tCode;

This is to check what is assigned I can actually see that e has been assigned: IDL:Currency/Convertor/unknownCode:1.0

Any idea why?
Re: Ass 1 Q3.2 - Can't "catch" error code
April 03, 2006 11:42AM
To access the actual currency code you would need something like:

cout << "Unknown code is " << e.currencyCode << endl;

Re: Ass 1 Q3.2 - Can't "catch" error code
April 03, 2006 11:49AM
Thanks for everything. It working well now.
Sorry, only registered users may post in this forum.

Click here to login