<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Activate and deactivate error handling with exceptions</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="rarexception.isusingexceptions.html">RarException::isUsingExceptions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.zip.html">Zip</a></div> <div class="up"><a href="class.rarexception.html">RarException</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="rarexception.setusingexceptions" class="refentry"> <div class="refnamediv"> <h1 class="refname">RarException::setUsingExceptions</h1> <p class="verinfo">(PECL rar >= 2.0.0)</p><p class="refpurpose"><span class="refname">RarException::setUsingExceptions</span> — <span class="dc-title">Activate and deactivate error handling with exceptions</span></p> </div> <div class="refsect1 description" id="refsect1-rarexception.setusingexceptions-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>RarException::setUsingExceptions</strong></span> ( <span class="methodparam"><span class="type">bool</span> <code class="parameter">$using_exceptions</code></span> )</div> <p class="para rdfs-comment"> If and only if the argument is <strong><code>TRUE</code></strong>, then, instead of emitting warnings and returning a special value indicating error when the UnRAR library encounters an error, an exception of type <span class="type"><a href="class.rarexception.html" class="type RarException">RarException</a></span> will be thrown. </p> <p class="para"> Exceptions will also be thrown for the following errors, which occur outside the library (their error code will be -1): </p> <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> attempting some operations on a closed <span class="type"><a href="class.rararchive.html" class="type RarArchive">RarArchive</a></span> object or a <span class="type"><a href="class.rarentry.html" class="type RarEntry">RarEntry</a></span> object relative to the first; </span> </li> <li class="listitem"> <span class="simpara"> attempting to get an entry that does not exist with <span class="methodname"><a href="rararchive.getentry.html" class="methodname">RarArchive::getEntry()</a></span>. </span> </li> </ul> </div> <div class="refsect1 parameters" id="refsect1-rarexception.setusingexceptions-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">using_exceptions</code></em></span> <dd> <p class="para"> Should be <strong><code>TRUE</code></strong> to activate exception throwing, <strong><code>FALSE</code></strong> to deactivate (the default). </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 examples" id="refsect1-rarexception.setusingexceptions-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-775"> <p><strong>Example #1 <span class="function"><strong>RarException::setUsingExceptions()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">isUsingExceptions</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$arch </span><span style="color: #007700">= </span><span style="color: #0000BB">RarArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">"does_not_exist.rar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$arch</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">setUsingExceptions</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">RarException</span><span style="color: #007700">::</span><span style="color: #0000BB">isUsingExceptions</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$arch </span><span style="color: #007700">= </span><span style="color: #0000BB">RarArchive</span><span style="color: #007700">::</span><span style="color: #0000BB">open</span><span style="color: #007700">(</span><span style="color: #DD0000">"does_not_exist.rar"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$arch</span><span style="color: #007700">); </span><span style="color: #FF8000">//not reached<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> bool(false) Warning: RarArchive::open(): Failed to open does_not_exist.rar: ERAR_EOPEN (file open error) in C:\php_rar\trunk\tests\test.php on line 3 bool(false) bool(true) Fatal error: Uncaught exception 'RarException' with message 'unRAR internal error: Failed to open does_not_exist.rar: ERAR_EOPEN (file open error)' in C:\php_rar\trunk\tests\test.php:8 Stack trace: #0 C:\php_rar\trunk\tests\test.php(8): RarArchive::open('does_not_exist....') #1 {main} thrown in C:\php_rar\trunk\tests\test.php on line 8 </pre></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-rarexception.setusingexceptions-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="rarexception.isusingexceptions.html" class="methodname" rel="rdfs-seeAlso">RarException::isUsingExceptions()</a> - Check whether error handling with exceptions is in use</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="rarexception.isusingexceptions.html">RarException::isUsingExceptions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.zip.html">Zip</a></div> <div class="up"><a href="class.rarexception.html">RarException</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>