Wednesday, April 07, 2010

System error support in C++0x - part 1

Among the many new library features in C++0x is a little header called <system_error>. It provides a selection of utilities for managing, well, system errors. The principal components defined in the header are:

  • class error_category
  • class error_code
  • class error_condition
  • class system_error
  • enum class errc

I had a hand in the design of this facility, so in this series of posts I will try to capture the rationale, history, and intended uses of the various components.

Where to get it

A complete implementation, and one that supports C++03, is included in Boost. I'd guess that, at this point in time, it is probably the best tested implementation in terms of portability. Of course, you have to spell things starting with boost::system:: rather than std::.

An implementation is included with GCC 4.4 and later. However, you must compile your program with the -std=c++0x option in order to use it.

Finally, Microsoft Visual Studio 2010 will ship with an implementation of the classes. The main limitation is that the system_category() does not represent Win32 errors as was intended. More on what that means later.

(Note that these are just the implementations that I am aware of. There may be others.)


Overview

Here are the types and classes defined by <system_error>, in a nutshell:

  • class error_category - intended as a base class, an error_category is used to define sources of errors or categories of error codes and conditions.
  • class error_code - represents a specific error value returned by an operation (such as a system call).
  • class error_condition - something that you want to test for and, potentially, react to in your code.
  • class system_error - an exception used to wrap error_codes when an error is to be reported via throw/catch.
  • enum class errc - a set of generic error condition values, derived from POSIX.
  • is_error_code_enum<>, is_error_condition_enum<>, make_error_code, make_error_condition - a mechanism for converting enum class error values into error_codes or error_conditions.
  • generic_category() - returns a category object used to classify the errc-based error codes and conditions.
  • system_category() - returns a category object used for error codes that originate from the operating system.

Principles

This section lists some of the guiding principles I had in mind in designing the facility. (I cannot speak for the others involved.) As with most software projects, some were goals at the outset and some were picked up along the way.

Not all errors are exceptional

Simply put, exceptions are not always the right way to handle errors. (In some circles this is a controversial statement, although I really don't understand why.)

In network programming, for example, there are commonly encountered errors such as:

  • You were unable to connect to a remote IP address.
  • Your connection dropped out.
  • You tried to open an IPv6 socket but no IPv6 network interfaces are available.

Sure, these might be exceptional conditions, but equally they may be handled as part of normal control flow. If you reasonably expect it to happen, it's not exceptional. Respectively:

  • The IP address is one of a list of addresses corresponding to a host name. You want to try connecting to the next address in the list.
  • The network is unreliable. You want to try to reestablish the connection and only give up after N failures.
  • Your program can drop back to using an IPv4 socket.

Another requirement, in the case of Asio, was a way to pass the result of an asynchronous operation to its completion handler. In this case, I want the operation's error code to be an argument to the handler callback. (An alternative approach is to provide a means to rethrow an exception inside the handler, such as .NET's BeginXYZ/EndXYZ asynchronous pattern. In my opinion, that design adds complexity and makes the API more error-prone.)

Last, but not least, some domains will be unable or unwilling to use exceptions due to code size and performance constraints.

In short: be pragmatic, not dogmatic. Use whatever error mechanism suits best in terms of clarity, correctness, constraints, and, yes, even personal taste. Often the right place to make the decision between exception and error code is at the point of use. That means a system error facility should support both.

Errors come from multiple sources

The C++03 standard recognises errno as a source of error codes. This is used by the stdio functions, some math functions, and so forth.

On POSIX platforms, many system operations do use errno to propagate errors. POSIX defines additional errno error codes to cover these cases.

Windows, on the other hand, does not make use of errno beyond the standard C library. Windows API calls typically report their errors via GetLastError.

When one considers network programming, the getaddrinfo family of functions uses its own set of error codes (EAI_...) on POSIX, but shares the GetLastError() "namespace" on Windows. Programs that integrate other libraries (for SSL, regular expressions, or whatever) will encounter other categories of error code.

Programs should be able to manage these error codes in a consistent manner. I'm especially concerned with enabling composition of operations to create higher-level abstractions. Combining system calls, getaddrinfo, SSL and regular expressions into one API should not force the user of that API to deal with an explosion of error code types. The addition of a new error source to the implementation of that API should not change the interface.

Be user-extensible

Users of the standard library need to be able to add their own error sources. This ability may just be used to integrate a third-party library, but is also tied in with the desire to create higher-level abstractions. When developing a protocol implementation such as HTTP, I want to be able to add a set of error codes corresponding to the errors defined in the RFC.

Preserve the original error code

This was not one of my original goals: my thinking was that the standard would provide a set of well-known error codes. If a system operation returned an error, it was the responsibility of the library to translate the error into a well-known code (if such a mapping made sense).

Fortunately, someone showed me the error of my ways. Translating an error code discards information: the error returned by the underlying system call is lost. This may not be a big deal in terms of program control flow, but it matters a lot for program supportability. There is no doubt that programmers will use a standardised error code object for logging and tracing, and the original error may be vital in diagnosing problems.

This final principle segues nicely into my topic for part 2: error_code vs error_condition. Stay tuned.

91 comments:

Anonymous said...

excellent article !

This is also good material for your book :)

regards
jose

Unknown said...

I really appreciate this content and discussion about error handling.

It looks like this subject is the least commented when it comes to talk about C++ new features. That's sad.

I've checked a bunch of recent books and it's rare to have any mention of error_condition for example.

Gryffin said...

std::system_error is the type of the exception thrown by various library functions (typically the functions that interface with the OS facilities. https://accesselitenow.com/

ßҽ𝜏 said...

We absolutely love your blog and find almost all of your post’s to be just what I’m looking for.
Does one offer guest writers to write content for you personally?
I wouldn’t mind publishing a post or elaborating on a number of the subjects you write with regards to here.

Again, awesome web log! 카지노사이트

ßҽ𝜏 said...

토토사이트 Hey There. I found your weblog using msn. This is an extremely smartly
written article. I’ll be sure to bookmark it and return to learn extra of your helpful information. Thanks for the post.
I’ll certainly return.

ßҽ𝜏 said...

Great goods from you, man. I have understand your stuff previous to and you are just extremely fantastic. I really like what you’ve acquired here, really like what you are saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I cant wait to read far more from you. This is really a great site. 토토사이트

UFABET1688 said...

Thanks a lot for sharing this with all people you actually know what you're speaking approximately! Bookmarked. Please additionally visit my web site =). We may have a link alternate arrangement among us. ufabet

UFABET1688 said...

Much obliged to you for your post, I search for such article along time, today I discover it at long last. this post give me heaps of prompt it is extremely helpful for me. ยูฟ่า168

Tom said...

Hey guys! If is wish to be the best with essay and dont know he excellent service for it check this rewrite essay service and go for it! This is it guys! This you chacnec so go fot it and be the best! Enjoy!

Majortotosite Pro said...

I got this web site from my friend who informed me regarding this website and at the moment this time I am visiting
this web page and reading very informative content here. 토토사이트

Igoal+ said...

There are many different games to choose from.
kingmaker ติดต่อ

Igoal said...

I really enjoyed your blog Thanks for sharing such an informative post.
cq9 slot ดาวน์โหลด

truthgame said...

Thank you very much for this great post
truthbet

imjeomin said...

Thank you very much for this great post
chudjenbet.com

huaydee said...

Great post thank you.huayonline

Anna said...

Despite the high number of gaming selections, there are https://dota2-bets.net/dota-2-item-betting/ not many betting websites that offer these versions. Many sites claim to do so but are only scam websites where gamblers are likely to lose their funds. Hence, finding a good and legal betting platform to play DOTA 2 jackpot and other casino versions of the popular game can be challenging.

Anonymous said...





sublime text crack

witham said...

Here at Gold Medal Accounting, we offer a comprehensive range of Accounting and Bookkeeping services designed to suit the customized needs of individuals, businesses, sole traders, partnerships and Companies.

Dijital Pazarlamacilar said...

Reklam Kampanyası Nedir Promosyon reklamcılığının tanımı, müşterilere satın almaya teşvik eden pazarlamadır. Tüm reklamlar satın almayı teşvik etmekle ilgilidir, ancak promosyon reklamları insanları bu özel indirim/BOGO/ücretsiz nakliye teklifi gece yarısı sona ermeden hemen önce yapmaya teşvik eder! Fat Guy Media , teşvik edici saatin tıkır tıkır işleyen karışımının, promosyon reklamcılık örneklerini diğer reklamcılık yaklaşımlarından ayırdığını söylüyor.


Promosyon reklamlarının bir son teslim tarihi vardır: Fiyatlar düşerken bu hafta satın alın, biz ücretsiz kargo sunarken satın alın, bu hafta sonu yarışmamıza katılırsanız bir iPad kazanın. Doğru yapılır, oldukça etkilidir.

Promosyon Reklam Örnekleri
Promosyon reklamcılığı, diğer reklam biçimleriyle aynı medyayı kullanabilir. Bir gazete ilanı çıkarırsanız, ilk kez müşteriler için peyzaj hizmetinizde yüzde 10 indirim sunan kuponları dahil edebilirsiniz. Ayrıca TV ve radyo sahalarında da çalıştırabilirsiniz; Mağazanız bu hafta sonu özel bir indirim yapıyorsa, büyük olasılıkla buna sürüş süresi radyo reklamlarınızda atıfta bulunmak isteyeceksiniz.

21. yüzyılda dijital medya, bazı satış promosyonlarında rol oynamaktadır. Örneğin Hootsuite , tıpkı Facebook veya Twitter'da olduğu gibi, insanların Instagram akışlarına reklam yerleştirmek için ödeme yapabileceğinizi söylüyor. Instagram görsel bir ortamdır, bu nedenle onu yeni tamamladığınız ev tadilatını veya mağazanızın sonbahardaki İtalyan ayakkabı koleksiyonunu vurgulamak için kullanabilirsiniz. Ardından, hızlı yanıtları teşvik etmek için bunu bir satış promosyonu ile birleştiriyorsunuz. E-posta ve metin mesajları diğer seçenekleriniz arasındadır.

Bu tür satış promosyonları dikkatli bir planlama gerektirir. Instagram reklamları ve TV izleme süresi ucuz değildir, bu nedenle yatırımınızın getirisini en üst düzeye çıkarmanız gerekir. Örneğin, küçük, yerel bir işletmeyseniz, yerel radyo veya reklam panosu, televizyondan daha uygun maliyetli olabilir. Hedef kitlenizi ve onlara nereden ulaşabileceğinizi düşünmelisiniz.

Örneğin, potansiyel müşterilerinizin yalnızca bir kısmı basılı gazeteyi okuyorsa, basılı bir promosyon için para harcamaya değmeyebilir. Instagram, harika görsellerle bir şeyleri tanıtmak için harika çalışıyor, ancak her ürün veya hizmetin göz alıcı unsurları yoktur.

Satış Promosyonu Türleri
AmeriCommerce , indirimlerin en popüler satış promosyonu türlerinden biri olduğunu söylüyor. Promosyon indirimi tanımı, anında satın almayı teşvik etmek için tasarlanmış bir fiyat indirimi olmasıdır; Kara Cuma ve Siber Pazartesi satışları klasik örneklerdir. Doğru indirimi hesaplamak zor olabilir. Müşterileri çekecek kadar büyük olmalı ama kârlılığınızı incitecek kadar büyük olmamalıdır.

Ücretsiz kargo ve ücretsiz iade, özellikle internet şirketleri için bir başka etkili taktiktir. Minimum satın alma tutarıyla ücretsiz gönderim sunan bazı işletmeler, bunu indirimle birleştirir: Yalnızca bu hafta, gönderim ​40 $ yerine 20$​'da ücretsiz ! Sadakat programları, sadık müşterileri hedefleyen bir promosyondur: Satın aldığınız her dokuz hamburger için, onda birini veya benzerini ücretsiz alırsınız.

Yarışmalar yıllardır bir tanıtım reklam aracı olmuştur. Temmuz ayında mağazanızdan alışveriş yapan beş müşterinin yeni bir buzdolabı veya lunapark gezisi kazanmak için rastgele seçileceğini duyurdunuz. Bu satış promosyonu işe yararsa, büyük ödülün maliyetini karşılamaya yetecek kadar çok iş getirmesi gerekir.

SEO consultants said...

SEO consultants great!

Fultech said...

It's really amazing piece of writing, I have got much clear idea regarding this post. Thank you so much for the post it is very helpful, keep posting such type of Article. Amazing!
easeus os2go crack
itop vpn premium crack
game fire pro crack
wondershare repairit crack
startallback crack
easeus recexperts crack
Also Visit fultech.org

A1office said...

Looking for a pdf editor that you can use online? Look no further than A1office! With our online pdf editor, you can easily make changes to your documents without having to download any software. Plus, our editor is easy to use and comes with a variety of features that will help you get the job done quickly and easily. Online Pdf Editor

nt88 said...

เว็บเล่นสล็อตได้เงินจริง แถมคืนยอดเสียให้กับสมาชิกของเราบ่อยมาก ต้องที่เว็บนี้เท่านั้น สล็อตแตกง่าย NT88 เล่นสล็อตได้เงินจริง

Nathalie said...

Such a great blog. Thanks for sharing this one. https://www.fencingdundee.co.uk/

Alicia Doss said...

Private lessons are for sale to TK/PAUD, SD, SMP, SMA, universities and the general public. International curriculum is presented, you know! Less tuition fees. Save about 40% more... click for more detail https://fisika-exed.blogspot.com/2022/06/les-privat-fisika-di-tanjung-priok.html

Unknown said...

Microsoft Office 2016 Product Key is server and client programming made by engineers. A refreshed type of it comes after the 2013 development. Furthermore, this assortment is reasonable for both sorts of clients. For Windows clients. Therefore it enables them to change, make, open, and save any record clearly to the cloud from the workspace.
Microsoft Office 2016 Product Key

Griselda Jore said...

An individual can teaching method listed here is described as unique teaching, where by one to three college students will certainly analysis beneath the instruction of any teacher ... go to https://privat-inggris.netlify.app/kursus-bahasa-inggris-jakarta-timur.html for further

C Sharp Programming Language for Web Development said...

Our c sharp development company can help you with system error support in C++. We have a team of experienced developers who can help you solve your system errors and get your C++ applications up and running again. Contact us today for a free!

Anonymous said...

GreatA Articles
alpinetimberltd.co.uk/


JacobHarman said...

The interval improvement chief is probable the most ideal choice for new organizations. In the first place, the startup designs the responsibility as per its ongoing financial plan by connecting such a specialist. Along these lines, the organization can work on its productivity without burning through a lot of cash on recruiting a full-time representative.

Second, development and a special vision are vital for new businesses. A break CTO can share his important specialized mastery and assist with characterizing a technique for creating innovation arrangements that will help the organization later on>> interim cdo for hire

Hilton Hosier said...

The most beneficial Jabodetabek private tutoring for kindergarten, elementary, junior high school. The most effective private teachers graduated from well-known state universities. The closest tutoring place online to the house at low cost ... visit https://privat-matematika.vercel.app/les-privat-matematika-grogol-petamburan.html for more details

안전놀이터 said...

If you allow me, I will try to refer to your article when I write. Thanks for helping me. :) 안전놀이터

Larry said...

I am truly pleased to discover this website. Thanks a lot! contact us today

Anonymous said...

That content post was fantastic. I'll very certainly return to your post. Well done! Gutter Contractors

Anonymous said...

Awesome content. Thanks for sharing this. Very interesting topic to write a blog. website

Unknown said...

This is nice and informative, containing all information and a great topic. www.insulationcoquitlam.com

Guest said...

Thank you for sharing such useful information. Continue to spread the word about your excellent work. Siding Service

Anonymous said...

Thanks! I love seeing posts that understand the value of providing a quality resource for free. Roof Maintenance Service

Guest said...

Glad to visit this site, I like the information you shared here. https://www.contractorlethbridge.com

see here said...

The letter I indicates a global error, which can be reported by any component. For example, the error, GODH 002 E means that a file open error ( 002 ) occurred in NameHunter (H).

Anonymous said...

What a very nice system you have. Thanks https://scottkeeverseo.com/

MaryDunn said...

Do you want to bring your startup idea to life? If he's technical, we're sure you've had trouble finding the right angular developer for your idea. It is not necessary to select each specialist on your own, trust our company to find an angular resume for you. Come in and our experts will leave you with no questions.

Guest said...

Nice post, will be sharing this with my fellow friends. Appliance Pros of Kitchener

hrdnmxdvlp said...

I found a useful article. It talks about microsoft dynamics ax project management. If you are interested in these points, then qualified and experienced developers will definitely help you to simplify the collection and management of your company's data, track and expand your potential customer base and also achieve your planned business expansion goals.

Unknown said...

Hello everyone, I want to recommend you a site where you can hire cloud integration and automation developers for any of your business projects and for any criteria and requests you set. It will not be difficult for you to hire the right candidate, consider all the services and types of specialists that will definitely suit you, and it is not difficult to hire them, you just have to leave your small response.

Anonymous said...

You can use an adverb checker as a tool to locate adverbs in sentences. You may make sure that your writing is more precise and impactful by using the help of professionals. If you need an additional consultation with it, I recomend you to visit our website. Parts of speech are frequently searched, but not everyone will be able to match what we provide.

Ziyyara Edutech said...
This comment has been removed by the author.
Guest said...

Amazing! I love this post so much. Thanks a lot! go here

Ment19711 said...

Lack of experience with the topic is one of the struggles people face when writing original content. As a result, they find it difficult to generate unique, in-depth, and informative articles, and they often ask themselves how to check originality of paper Rather than actually trying to help with a helpful resource, a lot of people go through the motions. And there is a general struggle.

Debra McRae said...

Hello! Do you want your AI to be popular with users? Those AIs that work as video annotation software claim great success. In order to teach your AI to recognize boring elements on a video, you need a data labeler that knows how to provide information to your AI and train it according to the best methods and practices.

Fenech said...

I enjoyed reading your post and look forward to reading more of your work in the future. go here

Anonymous said...

Great idea so far! Thanks https://amicoglobal.com/

Stephen said...

This is the best post I have ever seen. Very clear and simple. Mid-portion Is quite interesting though. Keep doing this. I will visit your site again. eren yeager jacket

Guest said...
This comment has been removed by the author.
Guest said...

Extraordinary Share! Aw, this was a truly decent post. I thought I might want to carefully record like this also - taking time and genuine work to make an awesome article. Thanks a lot! Burnaby Siding Installation

Anonymous said...

Good Data posted! Thanks www.eokitchen.com/

Horea said...

Happy that you have been very generous sharing this troubleshooting hack to the public. Many thanks for that!
check our services

Joana said...

I feel like I need to learn and discover more about it here. Fencing & Deck Pros of Milton

Sheryl Carter said...

Definitely a life saver for a lot of people working on the technical side of the business.
marketing agencies Tampa Florida

Ivee said...

Hey, the guy's! I am so happy about this site. Thank you. Residential Window Cleaners in Coquitlam

New Paving Company said...

Great idea so far! Although resin driveways are considered low maintenance, they still require regular maintenance. If you care for them correctly, a resin driveway can last for 25 years. But be aware of the potential problems of poorly installed resin driveways, as they can create a bad reputation for the industry. Resin is a complicated substance, and requires exact ratios of ingredients, the correct temperature and humidity levels, and proper moisture conditions. The first sign of a damaged driveway may take months to manifest. visite site

Anonymous said...

Thanks for sharing this article and illuminating us. puzzlegems.com

Prestige Park Grove said...

Yes, you do contribute significantly to the conversation with your knowledge, and the worth of your views is on par with the opulent services provided by Prestige Park Grove. We sincerely appreciate your assistance.

Provident Ecopolitan said...

Excellent work on this post! Your claims are well-supported by rigorous study, which is similar to the level of detail paid to projects such Provident Ecopolitan.

Anonymous said...

You have a very nice output! Post Offices

Anonymous said...

You have a good content! Thanks st pete fishing charters

Anonymous said...

System error support in C++0x - part 1 is a great detailed post that helps. I like more informative posts to learn more about this topic. While using the services from this website http://hermitageplumbers.com/ I found amazing results and it brings me here to get the detail here.

Anonymous said...

Your writing has a way of making me feel like I'm having a conversation with a friend. It's a rare talent | https://online-application.org/social-security-administration-office/oklahoma/

Southern Star said...

You make a strong argument against the status quo in your piece. You clearly put a lot of thought and emotion into this. eager for more to come. Prestige Southern Star

Anonymous said...

I'd love to see more posts like this. It's a fresh take on a common topic. https://www.poseidonfishingcharters.com/

Anonymous said...

I'm so happy with the output! Thank you applicationfiling.com/

Kyzer said...

Such great content you shared here. scissor lock gates

Anonymous said...

Yey! thank you for this amazing output. https://scottkeeverseo.com/

Anna said...

Thanks for this great information you shared. Collierville Flooring Pros Collierville TN

veer said...

Sobha Neopolis agree with your new thought.

concrete repair expert said...

Very interesting information, worth recommending.

Anonymous said...

Thank you for keeping us posted with new content. concrete contractor near me

junk haulers near me said...

It's nice seeing this awesome site here again.

Kerstin said...

This is awesome! Thanks for this post. brazilian jiu jitsu classes

Jones said...

Understand the value of providing a quality resource for free. vaughan physical therapy

Anonymous said...

Thanks for the informative content you shared. Dalton Digital digital marketing agency

gclubvip888 said...

"แน่นอนว่านี่คือเกมชูโรงของ Gclub
เพราะทุกคนที่เล่นพนันออนไลน์
จะรู้จัก บาคาร่าออนไลน์ กันเป็นอย่างดี
เรียกได้ว่าเป็นเกมที่ทุก ๆ เว็บ
ต้องมีเกมนี้ไว้ให้เล่นแน่นอน
บอกเลยว่าสุดฮิตสุดปังเลยล่ะ จีคลับ888 royal online "

Best Jackets for Men and Women said...

I have to say this is really great post thanks for shared this. you should also try this Best jackets for men and women.
best jackets for men and women

Anonymous said...

The careful selection of visuals, coupled with the harmonious color palette, creates a cohesive and inviting atmosphere. It's clear that you view your blog as more than a platform for information; it's a carefully curated space where every element contributes to a holistic reader experience. Thank you for making the act of reading a truly delightful and enriching endeavor.

https://www.tampa-seo.org

Scarlett said...

Thanks for sharing! I found this information very helpful.

appliance repair and installation services
washing machine repair edmonton
refrigerator repair edmonton
freezer repair edmonton
cooktop repair
oven repair
dryer repair edmonton
dishwasher repair edmonton
microwave repair edmonton
ranges and stove repair

Augustine said...

Pretty great post. I wanted to mention that I've truly enjoyed surfing around

Vincenzo said...

Amazing performance located on doing this website online. Keep doing it

Cervantes said...

Fabulous entire performance on the subject of doing this business site

Rodriguez said...

Great performance on this website. I enjoyed browsing it, and will come back often

Livingston said...

The site style is perfect, the articles is actually nice :D Good job, cheers

Patterson said...

Excellent quality writing, it is uncommon to see a nice blog like this one nowadays