|
George_George wrote: If this were Bjarne's point, I will have no question.
You can email Stroustrup!
George_George wrote: But as I showed to you, there is ways to catch exception from constructor of global variable
Do you think I don't know the way catching inside the ctor?! I have been using C++ for ten years.
Maxwell Chen
|
|
|
|
|
George_George wrote: I have read again the chapter and Bjarne only mentioned,
Stop messing with Bjarne's book. It is more of a reference book. It would be of great use after you've mastered the language. You seriously need a beginners book.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Anyway, how do you understand his (Bjarne) points?
regards,
George
|
|
|
|
|
George_George wrote: Anyway, how do you understand his (Bjarne) points?
Probably a bit better than you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Why not write down his points and correct me (make me convinced)?
regard,
George
|
|
|
|
|
Because we surrendered!
Maxwell Chen
|
|
|
|
|
Did you even read his post ?
The problem is simply that if the constructor throws an exception, you'll never be able to catch it if it is a global object. That's what the author was speaking about. Not about something that you can catch in your constructor.
What's the point of your example ?? You throw something that is caught two lines under. Why do you need to throw an exception for such a thing ? That's just totally not adapted.
But now, how can you inform the users of your object that something went wrong during construction of the object ? Well, in general you throw an exception out of your constructor.
|
|
|
|
|
Thanks Cedric,
1.
Cedric Moonen wrote: What's the point of your example ?? You throw something that is caught two lines under. Why do you need to throw an exception for such a thing ? That's just totally not adapted.
I simulate exception from real world. In real word of constructor, there may be exceptions like bad_alloc something, in this sample, I make it easy by using throw (0) just to show my concept.
2.
Cedric Moonen wrote: But now, how can you inform the users of your object that something went wrong during construction of the object ? Well, in general you throw an exception out of your constructor.
In the exception handler of constructor.
3.
How do you understand Bjarne's point? As I showed, exception in initialization of constructor can be caught and handled.
regards,
George
|
|
|
|
|
George_George wrote: In the exception handler of constructor.
Sorry, but that doesn't make sense at all. By "users", I didn't mean real person that manipulate your program but part of your program that use your class. In that case, you would like to know that your object failed to construct so that you can take specific actions. The best way to do it is to throw an exception from within your constructor. Let's take an example:
void MyFunc<br />
{<br />
try<br />
{<br />
CDummyClass test();<br />
test.DoSomething();<br />
}<br />
catch (....)<br />
{<br />
}<br />
}
You cannot design all your classes so that they don't throw an exception in their constructor just because *somebody might be one day* using it as a global object.
And in general, in a specific object, you don't want to do something specific if an error occurs but let the user (part of the programm) manage the error in a specific way (because it knows how to handle the error).
|
|
|
|
|
Hi Cedric,
You misunderstand my point. My point is you can do anything you like, for example, terminate the program or rethrow exception from constructor of global variable. Agree?
Does how to do in exception handler matters much to my original question?
regards,
George
|
|
|
|
|
George_George wrote: Agree?
No, not at all. Suppose you use a Database class that is coming from a specific library that has been developed by a company other than yours. This database class throws an exception if it cannot be constructed.
What will you do ? Ask them to send you the source code because you want to add a specific error handling there ?
Also, if you develop such a class, you sometimes DO NOT WANT to know what to do on an error. Because it is totally bad design to have all the classes know how to manage the errors themselves.
Suppose that you develop this database class. When you use it to connect a specific database in the constructor, you want to check if the connection was successfull or not. If it failed, the only thing you would like to do is connect to another database. Sometimes later in your program, you want to use the same database class to connect another database but there, if it fails, you just want to log the information in a log file because it is not critical. Still in another part of your program, you want to reuse the same class but if the connection fails, you want to display a message box to the user and exit the program.
So, how are you gonna managing all of that in your class constructor ? That will become a big mess. It is not the purpose of the database class to manage the errors because it's simply not its job.
If you fail to understand that, you really should get out of your books and program for real because it seems you are totally disconnected from the 'real world programming'. It's not that hard to understand, is it ?
|
|
|
|
|
Thanks Cedric!
I agree with you. Your experience is shining.
regards,
George
|
|
|
|
|
George_George wrote: Am I correct?
Have you considered discussing this with the author that made the claim?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi DavidCrow,
Do you have his email or MSN account?
I suggest to bring Bjarne to this forum to help to answer.
regards,
George
|
|
|
|
|
George_George wrote: Do you have his email or MSN account?
Surely you can Google for this.
George_George wrote: I suggest to bring Bjarne to this forum to help to answer.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello friends
I am using VC++ 6.0 for writing a multi threaded application. But I am facing problems when I try to Update a recordset (CRecordset object) from multiple threads running simultaneously
please help
Ranojay
|
|
|
|
|
Have a look at critical sections - they could be your friend.
CreateCriticalSection<br />
EnterCriticalSection<br />
LeaveCriticalSection<br />
DestroyCriticalSection (? - could be delete)
Good luck,
Iain.
|
|
|
|
|
Thank you Sir for your help
But the functions
EnterCriticalSection<br />
LeaveCriticalSection<br />
are giving error messages while in use
can you be more specific about how to use them
thanks again
|
|
|
|
|
I have *never* had one of those functions giving me an error. The only thing I can think of is that you've not initialised the critical section before using it. Look on
MSDN for EnterCriticalSection. One of the links take you to an example page for critical sections. (Copied below)
I would avoid the use of a global variable, and make the critical section a co-member of a class with your recordset, but I hope you'll get the idea.
Iain.
CRITICAL_SECTION CriticalSection;
void main()
{
...
InitializeCriticalSection(&CriticalSection);
...
DeleteCriticalSection(&CriticalSection)
}
DWORD WINAPI ThreadProc( LPVOID lpParameter )
{
...
__try
{
EnterCriticalSection(&CriticalSection);
}
__finally
{
LeaveCriticalSection(&CriticalSection);
}
...
}
|
|
|
|
|
Thanks again
I will try that. Actaully I am using the CWinThread Run() function from a CWinThread derived class
and doing the simultaneous update of the CRecordSet object and not AfxBeginthread function
will that work too?
anyway thank you very much for your help
and I will keep you disturbing
Thanks a lot
|
|
|
|
|
The code I showed was just an example - mostly for initialising the critical section.
Any code wrapped up by a Enter/LeaveCriticalSection pair will be callable from only one thread at a time. This includes any calls you make to a database, etc. It doesn't matter whether you make a thread using CWinThread::Run, AfxBeginThread, or ::CreateThread (mostly because they all end up being a call to BeginThread).
Iain.
|
|
|
|
|
Sir
I tried all the functions but it is still not working
some rows are surely getting updated but some of them are not
the error Mesage is No rows were affected by the update or delete operation.
has it any thing to do with the type of database I am using.Actually I am uising MS-ACCESS database.
may be ACCESS is not able to handle concurrent updates
|
|
|
|
|
Hi,
in my application I need to check if network is available. I have used the function InternetGetConnectedState.
But this function is not working on Windows 98. It always returns "Network connected State".
Is any other way, to check the network ( INTERNET ) connection on 98.
Regards
Somnath
|
|
|
|
|
Somnath_Mali wrote: It always returns "Network connected State".
And is that not right?
Have you tried IsNetworkAlive() or InternetCheckConnection() ?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
We have windows application, which should track if Desktop window is active and process some code if desktop is active.
Is any way to track the events which gets called when user selects "show desktop" from Quick launch OR "show desktop" from right click on task bar OR window+D.
Regards,
Somnath
|
|
|
|