Boost C++ Libraries: Ticket #11314: boost::gil::jpeg_read_dimensions(const char*) does not throw exceptions as it should https://svn.boost.org/trac10/ticket/11314 <p> boost::gil::jpeg_read_dimensions(const char*) is documented as followed (resides in .../boost/gil/extension/io/jpeg_io.hpp): </p> <pre class="wiki">/// \ingroup JPEG_IO /// \brief Returns the width and height of the JPEG file at the specified location. /// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file </pre><p> However, it does not always throw an exception. Instead it prints an error message and exits the program, which is how libjpeg by default handle its errors. </p> <p> See the following code: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/gil/extension/io/jpeg_io.hpp&gt; using std::cout; using std::cerr; using std::endl; using std::ios_base; namespace gil = boost::gil; int main(int argc, char **argv) { if(argc != 2) { cerr &lt;&lt; "Please supply a file name." &lt;&lt; endl; return 1; } const char *file = argv[1]; cout &lt;&lt; file &lt;&lt; ": " &lt;&lt; endl; try { gil::jpeg_read_dimensions(file); } catch(const ios_base::failure &amp;ib_f) { cerr &lt;&lt; "what: " &lt;&lt; ib_f.what() &lt;&lt; endl; } catch(...) { cerr &lt;&lt; "caught other exception!" &lt;&lt; endl; } cout &lt;&lt; "\nDone." &lt;&lt; endl; return 0; } </pre><p> I compile it using g++ 4.9.2 using the options </p> <pre class="wiki">-std=c++11 -I/usr/local/include -L/usr/local/lib -ljpeg -o bin main.cpp </pre><p> on a Mac OS X 10.9.5. </p> <p> See these three runs: </p> <pre class="wiki">$ ./bin non_existing.jpeg # this file does not exist non_existing.jpeg: what: file_mgr: failed to open file Done. </pre><pre class="wiki">$ ./bin existing_empty.jpeg # this file exist but is empty existing_empty.jpeg: Empty input file </pre><pre class="wiki">$ ./bin existing_non_jpeg.jpeg # this file exist and is not empty, but is not a jpeg existing_non_jpeg.jpeg: Not a JPEG file: starts with 0x62 0x6c </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11314 Trac 1.4.3 Mateusz Loskot Thu, 16 Feb 2017 10:52:54 GMT cc set https://svn.boost.org/trac10/ticket/11314#comment:1 https://svn.boost.org/trac10/ticket/11314#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">mateusz@…</span> added </li> </ul> Ticket Stefan Seefeld Sat, 01 Jul 2017 21:16:59 GMT owner changed https://svn.boost.org/trac10/ticket/11314#comment:2 https://svn.boost.org/trac10/ticket/11314#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Hailin Jin</span> to <span class="trac-author">Stefan Seefeld</span> </li> </ul> Ticket Mateusz Loskot Thu, 23 Aug 2018 19:39:59 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11314#comment:3 https://svn.boost.org/trac10/ticket/11314#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> First, the printed output comes from the libjpeg. Specifically, from <code>error_exit</code> routine. Apparently, old GIL IO did not override it with custom non-exiting handler. </p> <p> GIL in Boost 1.68 delivers completely re-implemented I/O extensions. The new version does provide custom <code>error_exit</code> which does not call hard <code>exit()</code> to abort the application, so the issue should be gone now. </p> <p> Closing as fixed. </p> <p> <a class="missing wiki">GitHub</a>? ref: <a class="ext-link" href="https://github.com/boostorg/gil/projects/4#card-12387661"><span class="icon">​</span>https://github.com/boostorg/gil/projects/4#card-12387661</a> </p> Ticket Mateusz Loskot Thu, 23 Aug 2018 19:40:16 GMT milestone changed https://svn.boost.org/trac10/ticket/11314#comment:4 https://svn.boost.org/trac10/ticket/11314#comment:4 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.69</span> </li> </ul> Ticket