Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, <code>catch(Exception ex)</code> is just the same as <code>catch(Exception)</code> with one difference only: in <code>catch(Exception ex)</code> we have an access to the exception class (error cause) instance. Usually you need an exception class instance to print out the original message:</p> <pre><code> try { ... } catch (AppServerException e) { Console.WriteLine("Application server failed to get data with the message:"); Console.WriteLine(e.Message); // &lt;- What's actually got wrong with it } </code></pre> <p>If you don't need the exception class instance, e.g. you plan just to consume the exception, the catch(Exception ex) syntax is excessive and catch(Exception) is prefferable:</p> <pre><code> try { c = a / b; } catch (DivideByZeroException) { c = Int.MaxValue; // &lt;- in case b = 0, let c be the maximum possible int } </code></pre> <p>Finally. <em>Do not catch general Exception class without re-throughing</em>: </p> <pre><code> try { int c = a / b; } catch (Exception) { // &lt;- Never ever do this! Console.WriteLine("Oh NO!!"); } </code></pre> <p>do you really want to code "whatever error (green fume from CPU included) had happend just print out "Oh No" and continue"? The pattern with Exception class is something like this:</p> <pre><code> tran.Start(); try { ... tran.Commit(); } catch (Exception) { // Whatever had happened, let's first rollback the database transaction tran.Rollback(); Console.WriteLine("Oh NO!"); throw; // &lt;- re-throw the exception } </code></pre>
    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. 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