Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > 65f8aa69c4b85eb2463f24ce9ff49b95 > files > 323

cimg-devel-1.5.9-3.mga5.i586.rpm

\hypertarget{structcimg__library_1_1CImgException}{\section{C\+Img\+Exception Struct Reference}
\label{structcimg__library_1_1CImgException}\index{C\+Img\+Exception@{C\+Img\+Exception}}
}


Instances of {\ttfamily \hyperlink{structcimg__library_1_1CImgException}{C\+Img\+Exception}} are thrown when errors are encountered in a {\ttfamily C\+Img} function call.  




Inherits exception.



Inherited by C\+Img\+Argument\+Exception, C\+Img\+Display\+Exception, C\+Img\+Instance\+Exception, C\+Img\+I\+O\+Exception, and C\+Img\+Warning\+Exception.

\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\hypertarget{structcimg__library_1_1CImgException_a586eee248fedb7de1b50219e14b99c7b}{const char $\ast$ \hyperlink{structcimg__library_1_1CImgException_a586eee248fedb7de1b50219e14b99c7b}{what} () const   throw ()}\label{structcimg__library_1_1CImgException_a586eee248fedb7de1b50219e14b99c7b}

\begin{DoxyCompactList}\small\item\em Return a C-\/string containing the error message associated to the thrown exception. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Instances of {\ttfamily \hyperlink{structcimg__library_1_1CImgException}{C\+Img\+Exception}} are thrown when errors are encountered in a {\ttfamily C\+Img} function call. 

\begin{DoxyParagraph}{Overview}

\end{DoxyParagraph}
\hyperlink{structcimg__library_1_1CImgException}{C\+Img\+Exception} is the base class of all exceptions thrown by {\ttfamily C\+Img}. \hyperlink{structcimg__library_1_1CImgException}{C\+Img\+Exception} is never thrown itself. Derived classes that specify the type of errord are thrown instead. These derived classes can be\+:


\begin{DoxyItemize}
\item {\bfseries C\+Img\+Argument\+Exception\+:} Thrown when one argument of a called {\ttfamily C\+Img} function is invalid. This is probably one of the most thrown exception by {\ttfamily C\+Img}. For instance, the following example throws a {\ttfamily C\+Img\+Argument\+Exception\+:} 
\begin{DoxyCode}
CImg<float> img(100,100,1,3); \textcolor{comment}{// Define a 100x100 color image with float-valued pixels.}
img.mirror(\textcolor{charliteral}{'e'});              \textcolor{comment}{// Try to mirror image along the (non-existing) 'e'-axis.}
\end{DoxyCode}

\item {\bfseries C\+Img\+Display\+Exception\+:} Thrown when something went wrong during the display of images in \hyperlink{structcimg__library_1_1CImgDisplay}{C\+Img\+Display} instances.
\item {\bfseries C\+Img\+Instance\+Exception\+:} Thrown when an instance associated to a called {\ttfamily C\+Img} method does not fit the function requirements. For instance, the following example throws a {\ttfamily C\+Img\+Instance\+Exception\+:} 
\begin{DoxyCode}
\textcolor{keyword}{const} CImg<float> img;           \textcolor{comment}{// Define an empty image.}
\textcolor{keyword}{const} \textcolor{keywordtype}{float} value = img.at(0);   \textcolor{comment}{// Try to read first pixel value (does not exist).}
\end{DoxyCode}

\item {\bfseries C\+Img\+I\+O\+Exception\+:} Thrown when an error occured when trying to load or save image files. This happens when trying to read files that do not exist or with invalid formats. For instance, the following example throws a {\ttfamily C\+Img\+I\+O\+Exception\+:} 
\begin{DoxyCode}
\textcolor{keyword}{const} CImg<float> img(\textcolor{stringliteral}{"missing\_file.jpg"});  \textcolor{comment}{// Try to load a file that does not exist.}
\end{DoxyCode}

\item {\bfseries C\+Img\+Warning\+Exception\+:} Thrown only if configuration macro {\ttfamily cimg\+\_\+strict\+\_\+warnings} is set, and when a {\ttfamily C\+Img} function has to display a warning message (see \hyperlink{namespacecimg__library_1_1cimg_a5ee7f021ed42b0ac32e1254414c3faab}{cimg\+::warn()}).
\end{DoxyItemize}

It is not recommended to throw \hyperlink{structcimg__library_1_1CImgException}{C\+Img\+Exception} instances by yourself, since they are expected to be thrown only by {\ttfamily C\+Img}. When an error occurs in a library function call, {\ttfamily C\+Img} may display error messages on the screen or on the standard output, depending on the current {\ttfamily C\+Img} exception mode. The {\ttfamily C\+Img} exception mode can be get and set by functions \hyperlink{namespacecimg__library_1_1cimg_a933d23f5cc8c7bd672541c5e758328ba}{cimg\+::exception\+\_\+mode()} and \hyperlink{namespacecimg__library_1_1cimg_a933d23f5cc8c7bd672541c5e758328ba}{cimg\+::exception\+\_\+mode(unsigned int)}.

\begin{DoxyParagraph}{Exceptions handling}

\end{DoxyParagraph}
In all cases, when an error occurs in {\ttfamily C\+Img}, an instance of the corresponding exception class is thrown. This may lead the program to break (this is the default behavior), but you can bypass this behavior by handling the exceptions by yourself, using a usual {\ttfamily try \{ ... \} catch () \{ ... \}} bloc, as in the following example\+: 
\begin{DoxyCode}
\textcolor{preprocessor}{#define "CImg.h"}
\textcolor{keyword}{using namespace }\hyperlink{namespacecimg__library}{cimg\_library};
\textcolor{keywordtype}{int} main() \{
  \hyperlink{namespacecimg__library_1_1cimg_a933d23f5cc8c7bd672541c5e758328ba}{cimg::exception\_mode}(0);                                    \textcolor{comment}{// Enable quiet exception
       mode.}
  \textcolor{keywordflow}{try} \{
    ...                                                       \textcolor{comment}{// Here, do what you want to stress the CImg
       library.}
  \} \textcolor{keywordflow}{catch} (\hyperlink{structcimg__library_1_1CImgException}{CImgException} &e) \{                                \textcolor{comment}{// You succeeded: something went
       wrong!}
    std::fprintf(stderr,\textcolor{stringliteral}{"CImg Library Error: %s"},e.\hyperlink{structcimg__library_1_1CImgException_a586eee248fedb7de1b50219e14b99c7b}{what}());   \textcolor{comment}{// Display your custom error message.}
    ...                                                       \textcolor{comment}{// Do what you want now to save the ship!}
    \}
  \}
\end{DoxyCode}