Skip to content

21. Catch/Throw, TypeOf()/.GetType(), Constructor

March 1, 2011

61. What is the difference between: catch(Exception e) { throw e;} and catch(Exception e) {throw;}?
Both versions will catch every exception thrown inside the preceding try block. The second rethrows the current exception, keeping its source and stack trace. The first changes the source and stack trace, making it appear that the exception has been thrown from this method, containing the try-catch block, precisely at the line where the fully qualified exception is thrown.

62. What is the difference between typeof(foo) and myFoo.GetType()?
type(foo) returns the objects type at compile time. myFoo.GetType() return the objects type at run time, following the format object dot method.

63. Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
The first constructor calls the base constructor in addition to its own parameter. This is useful if the base constructor initialized shared, common fields or implements code the  invoking constructor can use.

Happy Programming! =)

Source: mainly MSDN.

Advertisements

From → OOP

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: