c# - Using Try-Catch-Finally to handle arithmetic exceptions -


i try 2 different things (both have strong possibility of failure) , reason use "finally" statement run "safety" in case first 2 tries both fail.

take following example (no not code using in project!).

int 0 = 0; int 1 = 1;  try {     // throws ' cannot divide 0 ' error     int error = 1 / zero; }  catch {     // throws error again of course     int somenum = 1 / zero; }   {     messagebox.show("i can never make here ...");  } 

so, program following:

  1. attempt divide zero
  2. if step #1 fails, 'catch' statement run code (which should once again fail in example).
  3. if both steps #1 , #2 fail, program display messagebox in 'finally' statement.

am close one?

int 0 = 0; int 1 = 1;  try {     try     {         // throws ' cannot divide 0 ' error         int error = 1 / zero;     }      catch (dividebyzeroexception)     {         // throws error again of course         int somenum = 1 / zero;     } } catch (dividebyzeroexception) {     messagebox.show("i can never make here ..."); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -