Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have several options.</p> <ul> <li><p>You could not handle the exception at all :</p> <pre><code>public SetInt() { i = "OLAGH"; //This is bad!!! return i; } </code></pre></li> </ul> <p>Then the caller will need to handle the exception.</p> <ul> <li><p>If you want to handle the exception you can catch the error and handle it.</p> <pre><code>public SetInt() { try { i = "OLAGH"; //This is bad!!! return i; } catch (FailException ex) { return FAIL; } } </code></pre></li> </ul> <p>Note that it is bad practice to just catch the base Exception class. You should anticipate which errors may occur and try to handle them. Unanticipated errors and the result of bugs and should make a big noise so that you can be alerted to other problems and fix them.</p> <ul> <li><p>If you want to raise your own kind of exception, you could do :</p> <pre><code>public SetInt() { try { i = "OLAGH"; //This is bad!!! return i; } catch (FailException ex) { throw new SetIntFailException ( ex ); } } </code></pre></li> </ul> <p>Then it is the callers responsibility to handle the SetIntFailException rather than a CastFailException or whatever hundreds of other kind of exceptions your code may throw..</p> <ul> <li><p>If you want the caller to handle the exception, but you have some clean up you want to do, you can use finally :</p> <pre><code>public SetInt() { try { i = "OLAGH"; //This is bad!!! return i; } finally { // Cleanup. } } </code></pre></li> </ul> <p>The code in the finally block will always be called, even when there is an exception, but the error still gets raised to the caller.</p> <p><em>I am assuming that in your real code, it will at least compile! ;-)</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload