21. Is it a good practice to handle exceptions in code?
Yes, you must handle exceptions in code so that you can deal with any unexpected conditions that occur when a program is running. For example, dividing a number by zero or passing a string value to a variable that holds an integer value would result in an exception.
22. Explain the concept of constructor?
Constructor is an unique process of a class, which is called automatically when the sing of a class is created. It is created with the same name as the class and initializes all class members, whenever you access the class.
The main features of a constructor are as follows:
• Constructors do not have any return type.
• Constructors can be overloaded.
• It is not mandatory to declare a constructor; it is invoked automatically by .NET Framework.
23. Can you inherit private members of a class?
No, you cannot inherit private members of a class because private members are accessible only to that class and not outside that class.
24. Does .NET support multiple inheritance?
.NET does not support multiple inheritance directly because in .NET, a class cannot inherit from more than one class. .NET supports multiple inheritance through interfaces
25. How has exception handling changed in .NET Framework 4.0?
In .NET 4.0, a new namespace, System.Runtime.ExceptionServices, has been inagvrated which contains the following classes for handling exceptions in a better and advanced manner:
• HandleProcessCorruptedStateExceptionsAttribute Class - Enables managed code to handle the corrupted state exceptions that occur in an operating system. These exceptions cannot be caught by specifying the try...catch block. To handle such exceptions, you can apply this attribute to the method that is assigned to handle these exceptions.
• FirstChanceExceptionEventArgs Class - Generates an event whenever a managed exception first occurs in your code, before the common language runtime begins searching for event handlers.
No comments:
Post a Comment