Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Exceptions should be used for exceptional situations.</p> <p>From your example, if the window not being hidden is a typical event, it shouldn't throw an exception. If that is your function, then use a return value to indicate whether it was successful instead of throwing an exception. Then you can safely ignore the return value when you don't care if it succeeded or not.</p> <p>If you do not have control over that method, then you can wrap it in another method that catches the exception and turns it into a return value. E.g.</p> <pre><code>private boolean tryHideWindow() { try { hideWindow(); } catch (ReportedException ex) { return false; } return true; } </code></pre> <p>If you need some parameters of the exception to determine what to do, then you could return the exception instead.</p> <pre><code>private static class MyReturnType { private final Throwable thrown; private final OrigRtnType returnVal; public MyReturnType(Throwable thrown) { this.thrown = thrown; this.returnVal = null; } public MyReturnType(OrigRtnType returnVal) { this.thrown = null; this.returnVal = returnVal } public boolean wasExceptionThrown() { return thrown != null; } } private MyReturnType tryHideWindow() { try { OrigRtnType returnVal = hideWindow(); } catch (ReportedException ex) { return new MyReturnType(ex); } return new MyReturnType(returnVal); } </code></pre> <p>This is an answer to your question, but it is not necessarily a good idea. As others will doubless comment, using exceptions for program flow is less than ideal.</p>
    singulars
    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. 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.
 

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