c# - What is the behavior when throwing an exception without setting out parameter? -


What is defined behavior for C # when an exception is thrown before setting the value of a parameter, and then you Try to reach the parameter?

  Try the public zero DoSomething (int id, out control) {{int result = call (id)}; Control = new call control (result); } Hold (exception e) {new exception throw ("call fail", e); }} // Do Something else DoSomething (Control Out Control) {try {DoSomething (1, Out Control); } Hold () {// handle exception}} // control later; DoSomething (Control Out) control.Show ();   

The compiler usually complains about exiting the method before setting the parameter outside. It seems that it manipulates me by saving myself.

defined behavior C # when an exception is thrown before setting the value of a parameter , And then you try to reach the parameter?

You can not do this This variable will definitely not be definite, unless it is definitely specified before the method call.

If the variable was is definitely given before the method call, it will surely be specified definite - but before that method before , the value of the variable will remain untouched:

  class test {fixed zero zero trow (out int x) {throw new exception (;); } Fixed zero main () {int y = 10; Try {JustThrow (out y); } Hold {// ignore} console Write Row (Y); // still print 10}}    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -