473,549 Members | 5,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL sort throw exception?

200 New Member
Hello everyone,


In Bjarne's book, it is mentioned that sort of STL may throw exception, like sorting elements in a vector.

In what situation will sort throw exception? I can not find a case.


thanks in advance,
George
Jan 4 '08 #1
5 1950
weaknessforcats
9,208 Recognized Expert Moderator Expert
Where does he mention it??

The sort should not throw although exceptions can be thrown by predicates. You should always presume exceptions whenever you use STL algorithms.
Jan 4 '08 #2
oler1s
671 Recognized Expert Contributor
George, while we have been helping you, your behavior feels very similar to that of a help vampire. Furthermore, you seem to be posting to multiple boards at once. Also see http://cboard.cprogramming.com/showthread.php?t=97544. And http://www.eggheadcafe.com/software/...exception.aspx.

Starting multiple threads on the same question wastes people's time, as they are completely oblivious to other trains of thought. Perhaps you should review how to ask smart questions, an excellent article on the mentality and etiquette on technical forums.

EDIT: This is not the only thread George has been spamming multiple boards. Check his other questions. They have been multi-spammed everywhere, including Usenet.
Jan 4 '08 #3
George2
200 New Member
Hi weaknessforcats ,


You can refer to his book, appendix E, Standard-Library Exception Safety, in the 1st sample in E.1 (Introduction).

Where does he mention it??

The sort should not throw although exceptions can be thrown by predicates. You should always presume exceptions whenever you use STL algorithms.

regards,
George
Jan 5 '08 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
[
You can refer to his book, appendix E, Standard-Library Exception Safety, in the 1st sample in E.1 (Introduction).
He doesn't say that the sort throws an exception.

What is does say is that the code that compares two objects can throw an exception.

There's a difference.

It all comes down to using try/catch blocks liberally when writing C++. To not do that just invites a crash.
Jan 5 '08 #5
George2
200 New Member
Thanks weaknessforcats ,


My question is answered.

[

He doesn't say that the sort throws an exception.

What is does say is that the code that compares two objects can throw an exception.

There's a difference.

It all comes down to using try/catch blocks liberally when writing C++. To not do that just invites a crash.

regards,
George
Jan 7 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
458
by: Kerri | last post by:
Hi, I am new to .NET In my Error Logic on my Aspx pages when an error happens it hits my catch statement where I throw an Exception. My question is : what is the difference between Thwo Exception and Throw
3
3484
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? Is this because there could be an exception thrown when the code creates a std::exception? I would assume that is not the case. However, if I want...
17
1933
by: hplloyd | last post by:
Hi, I have a function that adds data to a database and I want to return true if the database was updated and false if there was a problem, so I am using a try... catch block... My problem is that I can return true ok is the routine succeeds but where do I put the return false; statement id the process fails - I get a compile error say...
6
5708
by: Arjen | last post by:
Hi, I'm reading the enterprise library documentation and there I see the throw statement. try { // run code } catch(Exception ex) {
1
2682
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting, paginantion or accepting the add and remove item events. What i am observing is that none of the vents are happening... (Sort, page, or item). I am sure I...
6
7848
by: Paul van Brenk | last post by:
When you run the Shuffle method often enough it will throw exception. And I can't figure out why. Anybody? Paul van Brenk the code: static void Shuffle(){ int ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
6
11633
by: Henryk | last post by:
I did a lot of delphi GUI programming recently. In my experience most of the time you just want to throw a standard exception with a descriptive message. Then all calling functions can handle this exception as they like and finally show a message to the user or not. Only in a few occasions I need some special exception types to behave...
28
2824
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't apply. Can somebody tell me why? Thanks, Jess
4
2224
by: George2 | last post by:
Hello everyone, In Bjarne's book, it is mentioned that sort of STL may throw exception, like sorting elements in a vector. In what situation will sort throw exception? I can not find a case. thanks in advance,
6
1951
by: jason.cipriani | last post by:
Consider this program, which defines a template class who's template parameter is the type of an exception that can be thrown by members of the class: === BEGIN EXAMPLE === #include <iostream> #include <string> using namespace std;
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7455
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.