Does Dispose still get called when exception is thrown inside of a using statement?

Yes, using wraps your code in a try/finally block where the finally portion will call Dispose() if it exists. It won’t, however, call Close() directly as it only checks for the IDisposable interface being implemented and hence the Dispose() method. See also: Intercepting an exception inside IDisposable.Dispose What is the proper way to ensure a … Read more

Does Java have a using statement?

Java 7 introduced Automatic Resource Block Management which brings this feature to the Java platform. Prior versions of Java didn’t have anything resembling using. As an example, you can use any variable implementing java.lang.AutoCloseable in the following way: try(ClassImplementingAutoCloseable obj = new ClassImplementingAutoCloseable()) { … } Java’s java.io.Closeable interface, implemented by streams, automagically extends AutoCloseable, … Read more

What happens if i return before the end of using statement? Will the dispose be called?

Yes, Dispose will be called. It’s called as soon as the execution leaves the scope of the using block, regardless of what means it took to leave the block, be it the end of execution of the block, a return statement, or an exception. As @Noldorin correctly points out, using a using block in code … Read more

What is the C# Using block and why should I use it? [duplicate]

If the type implements IDisposable, it automatically disposes that type. Given: public class SomeDisposableType : IDisposable { …implmentation details… } These are equivalent: SomeDisposableType t = new SomeDisposableType(); try { OperateOnType(t); } finally { if (t != null) { ((IDisposable)t).Dispose(); } } using (SomeDisposableType u = new SomeDisposableType()) { OperateOnType(u); } The second is easier … Read more

What are the uses of “using” in C#?

The reason for the using statement is to ensure that the object is disposed as soon as it goes out of scope, and it doesn’t require explicit code to ensure that this happens. As in Understanding the ‘using’ statement in C# (codeproject) and Using objects that implement IDisposable (microsoft), the C# compiler converts using (MyResource … Read more

The type or namespace name could not be found [duplicate]

See this question. Turns out this was a client profiling issue. PrjForm was set to “.Net Framework 4 Client Profile” I changed it to “.Net Framework 4”, and now I have a successful build. Thanks everyone! I guess it figures that after all that time spent searching online, I find the solution minutes after posting, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)