|
What am I doing? I want my template class to send an exception when one of input parameters is out of range.
How am I doing that? The main parts of the source code are presented below.
Does it work? Yes, it does. The exception is being sent and caught in the program passing wrong input parameters, error message is successfully displayed.
So, what is wrong? I receive a strange warning during compilation: Warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
I don't know what's wrong with it, but I don't like warnings... especially those that I don't understand. If you can tell me what the compliler (MS VC .NET) wants from me I will be very grateful to you. Thank you!!!
#define CLogicError std::logic_error
#define STRING std::string
class CMyError : public CLogicError
{
public:
CMyError(const STRING& what_arg) : CLogicError(what_arg) {};
};
template<class T> class TMy
{
...
T& operator()(const int nRow, const int nCol) throw (CMyError);
...
}
template<class T> T& TMy<T>::operator()(const int nRow, const int nCol) throw (CMyError)
{
...
}
The warning points to the line
T& operator()(const int nRow, const int nCol) throw (CMyError);
in class definition. It does not seem to like "throw (CMyError)" part. If I change it to "throw()" the compiler stops complaining.
|
|
|
|
|
It simply means that the compiler doesn't support exception specifications (semantically). That is, the compiler does not generate code to enforce the rule that the function can't throw *any* exception other than CMyError . You can try it out, try throwing any other exception, it will still be caught in the corresponding catch block, but according to the standard, it must result in a call to unexpected and then aborting of the program.
throw() means that your function is not allowed to throw exceptions at all, I don't know why that doesn't result in a warning? May be VC++.NET supports just that special case?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Senthil,
Thank you for the response.
throw() does not lead to any warnings at all. I tried as you suggested and in fact caught other exception as well. The debugger still reported about an "unhandled exception" though but did not abort my program. When I throw the correct type of exception the debugger does not report about an "unhandled exception". So, I assume you are right about the compiler not enforcing the exception type upon the function that throws exceptions.
Since it is actually one of the best compilers in the world, I am a little bit skeptical that it is a compiler's fault though. I suspect and, in fact, am more inclined to think that I have done something wrong. Maybe there is an option that I have to set to force the implementation of this exception restriction upon functions? I have not found any in the project settings that has anything to do with exceptions. Or else, may it have anything to do with templates, since they are implemented in *.h file rather than in *.cpp?
|
|
|
|
|
Since it is actually one of the best compilers in the world, I am a little bit skeptical that it is a compiler's fault though. I suspect and, in fact, am more inclined to think that I have done something wrong.
No, you haven't done anything wrong. MSVC.NET does not support exception specifications except throw() , as the compiler itself and Kumar point out.
For what is worth, exception specification has become in recent years to be regarded as a design flaw in C++, so you might consider not using it. Follow this link[^] for some explanations about why exception specification is probably best avoided.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thank you, Joaquín. It is pretty unfortunate that an ISO standard is not supported but I am going to follow your suggestion and avoid exception specifications. Thanks again!
|
|
|
|
|
i LIKE TO GET A ALGORITHM FOR SUBNETTING CLASS C NETWORK IN PROGRAMMING FORMAT SUCH AS C OR IN c++. IS THERE ANYONE WHO CAN HELP ME....PLZ HELP ME....I NEED THT AS SOON AS POSSIBLE...PLZ SEND IT THROUGH MY E-MAIL ADDRESS: zibran@cgscomm.net
I wish I'll get a reply form nyone....
Thnx to all for reading my msg.
Bye
ZIBRAM ISLAM
B.Sc(HONS) in CIS
M.Sc in Telecomm
|
|
|
|
|
is there any command-line software that could plot a graph from a file and output to a file,
|
|
|
|
|
You might be able to do something with this[^].
Lets be honest, isn't it amazing how many truly stupid people you meet during the course of the day. Carry around a pad and pencil, you'll have twenty or thirty names by the end of the day - George Carlin
Awasu 2.1.1 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
|
|
i want to create a batch file that input a c++ program the input are just integers can some give me an example of what i should do the input to the the file NNtest something like this maybe
NNtest.exe
1
0.1 0.001
3
35 5 3
3
but im not sure how to write this in a bat file
thanks
|
|
|
|
|
Try to save the data into a file and then use it as redirected input:
NNTest <AFile
|
|
|
|
|
How do you fill a CURRENCYFMT structure with the user's locale settings?
thanks.
|
|
|
|
|
|
But I need the locale info for the CURRENCYFMT struct. I want to get the user's locale settings for the CURRENCYFMT structure, change some of the members (lpCurrencySymbol, NegativeOrder) and then call GetCurrencyFormat().
|
|
|
|
|
Pass NULL in the Locale arg of GetCurrencyFormat() . See this[^] link.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Passing NULL for the Locale arg seems to stall the program. I'm not sure if I'm explaining my problem right. I don't just want to format a string with the user's locale settings. I want to get the the locale setting values for the CURRENCYFMT members, but then change some of the settings, and then call GetCurrencyFormat() to format the string. I may just be missing it, but I don't see anywhere in the documentation where GetCurrencyFormat() fills a CURRENCYFMT struct with the user's locale settings...
|
|
|
|
|
Ah.
This[^] page contains a code fragment that shows how to modify the locale's default currency symbol and pass the modified format to GetCurrencyFormat() . See the paragraph starting with "Another scenario would be ...". Hope this helps.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
hello
i need some example on how to use the mouse in a application
i tried everything and it doesnt work (even the microsoft page)
please i really need the help.
i would really apreciate
|
|
|
|
|
|
|
|
I've recently made a little server based on WinSock. Here is it:
#include <windows.h><br />
<br />
#pragma comment(lib, "wsock32.lib")<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)<br />
{<br />
WSADATA WsaDat;<br />
if (WSAStartup(MAKEWORD(2, 0), &WsaDat) != 0)<br />
{<br />
return 0;<br />
}<br />
SOCKET Socket;<br />
Socket = socket(AF_INET, SOCK_STREAM, 0);<br />
if (Socket == INVALID_SOCKET)<br />
{<br />
return 0;<br />
}<br />
SOCKADDR_IN SockAddr;<br />
SockAddr.sin_port = htons(666);<br />
SockAddr.sin_family = AF_INET;<br />
char Name[255];<br />
gethostname(Name, 255);<br />
HOSTENT *HostInfo;<br />
HostInfo = gethostbyname(Name);<br />
SockAddr.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)HostInfo->h_addr_list[0][0];<br />
SockAddr.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)HostInfo->h_addr_list[0][1];<br />
SockAddr.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)HostInfo->h_addr_list[0][2];<br />
SockAddr.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)HostInfo->h_addr_list[0][3];<br />
if (bind(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR) <br />
{ <br />
return 0;<br />
}<br />
listen(Socket, 8);<br />
SOCKET TempSock = SOCKET_ERROR; <br />
while (TempSock == SOCKET_ERROR)<br />
{<br />
TempSock = accept(Socket, NULL, NULL);<br />
}<br />
Socket = TempSock;<br />
char String[64];<br />
int ret = 0;<br />
while (1)<br />
{<br />
ret = recv(Socket, String, 64, 0);<br />
if (ret > 0)<br />
{<br />
}<br />
else<br />
{<br />
WSACleanup();<br />
return 0;<br />
}<br />
}<br />
WSACleanup();<br />
return 0;<br />
}
I want it to accept multiple simultaneous connections. How do I do it?
|
|
|
|
|
Your code is sitting in a loop, waiting for stuff to come in on the connection once it has been established.
Instead, hand the socket off to a worker thread to do that and go back and wait for a new connection. Or you can do everything using async I/O (a bit trickier).
Lets be honest, isn't it amazing how many truly stupid people you meet during the course of the day. Carry around a pad and pencil, you'll have twenty or thirty names by the end of the day - George Carlin
Awasu 2.1.1 [^]: A free RSS reader with support for Code Project.
|
|
|
|