UTF8 - Simple Library for Internationalization
Loading...
Searching...
No Matches
utf8::exception Class Reference

Exception thrown on encoding/decoding failure. More...

#include <utf8.h>

Inheritance diagram for utf8::exception:

Public Types

enum  cause { invalid_utf8 =1 , invalid_wchar , invalid_char32 }
 Possible causes.
 

Public Member Functions

 exception (cause c)
 Constructor.
 
const char * what () const noexcept
 Exception message.
 

Data Fields

cause code
 Condition that triggered the exception.
 

Detailed Description

Exception thrown on encoding/decoding failure.

Most UTF8 functions will throw an exception if input string is not a valid encoding.

So far there are two possible causes:

  • invalid_utf8 if the string is not a valid UTF-8 encoding
  • invalid_char32 if the string is not a valid UTF-32 codepoint.

You can handle a utf8::exception using code like this:

//...
catch (utf8::exception& e) {
if (e.code == utf8::exception::invalid_utf8) {
// do something
}
}
Exception thrown on encoding/decoding failure.
Definition utf8.h:41
cause code
Condition that triggered the exception.
Definition utf8.h:59

or you can simply use the exception message:

//...
catch (utf8::exception& e) {
cout << e.what() << endl;
}
const char * what() const noexcept
Exception message.
Definition utf8.h:51

The documentation for this class was generated from the following file: