Quick Links:

bal | bbl | bdl | bsl

Component bslstl_systemerror
[Package bslstl]

Provide a standard compliant system_error class. More...

Outline
Purpose:
Provide a standard compliant system_error class.
Classes:
bsl::system_error a standard compliant system_error class
Canonical Header:
bsl_system_error.h
Description:
This component defines class bsl::system_error, a class used for annotated exception objects about errno-style errors. In C++11 mode, the vendor-supplied <system_error> implementation is used instead, and the corresponding names from std are imported into bsl.
Usage:
In this section we show intended use of this component.
Example 1: Adding Annotation to an Error:
Suppose we want to add an informative message when a system error occurs and include that as part of an exception that we throw when reporting the error. We can use bsl::system_error to do that.
First, reset errno to avoid detecting old problems.
  errno = 0;
Then, do something that will fail and set errno.
  strtod("1e2000", 0);
Next, check that errno was actually set.
  assert(ERANGE == errno);
Finally, prepare an annotated exception and verify the annotation and the error code stored within it.
  bsl::system_error annotated(errno, generic_category(), "1e2000");
  assert(strstr(annotated.what(), "1e2000"));
  assert(static_cast<int>(bsl::errc::result_out_of_range) ==
         annotated.code().value());
  assert(&generic_category() == &annotated.code().category());