Ejecicios de programación

Solo disponible en BuenasTareas
  • Páginas : 8 (1795 palabras )
  • Descarga(s) : 0
  • Publicado : 30 de mayo de 2011
Leer documento completo
Vista previa del texto
1. Use inheritance to create an exception base class and various exception-derived classes. Write a program to demonstrate that the catch specifying the base class catches derived-class exceptions.

2. Write a C# program that demonstrates how various exceptions are caught with catch ( Exception exception )

3. Write a C# program that shows the importance of the order of exception handlers.Write two programs: One with the correct order of catch handlers, and one with an incorrect order (i.e., place the base class exception handler before the derived-class exception handlers). Show that if you attempt to catch a base-class exception type before a derived-class exception type, the derived-class exceptions are not invoked (which potentially yield logical errors in routine). Explain whythese errors occur.

4. Exceptions can be used to indicate problems that occur when an object is being constructed. Write a C# program that shows a constructor passing information about constructor failure to an exception handler that occurs after a try block. The exception thrown also should contain the arguments sent to the constructor.

5. Write a C# program that demonstrates rethrowing anexception.

6. Write a C# program that shows that a method with its own try block does not have to catch every possible exception that occurs within the try block. Some exceptions can slip through to, and be handled in, other scopes.

Ejercicios por equipo
1. An exception is an indication of a problem that occurs during a program’s execution.
2. Exception handling enables programmers tocreate applications that can resolve exceptions, often allowing a program to continue execution as if no problems were encountered.
3. Exception handling enables programmers to write clear, robust and more fault-tolerant programs
4. Exception handling enables the programmer to remove error-handling code from the “main line” of the program’s execution. This improves program clarity and enhancesmodifiability.
5. Exception handling is designed to process synchronous errors, such as out-of-range array subscripts, arithmetic overflow, division by zero, invalid method parameters and memory exhaustion.
6. Exception handling is not designed to process asynchronous events, such as disk-I/O completions, network-message arrivals, mouse clicks and keystrokes.
7. When a method detects an errorand is unable to handle it, the method throws an exception. There is no guarantee that there will be an exception handler to process that kind of exception. If thereis, the exception will be caught and handled.
8. In debug mode, when the program detects an uncaught exception, a dialog box appears that enables the programmer to view the problem in the debugger or continue program execution byignoring the problem that occurred.
9. A try block consists of keyword try followed by braces ({}) that delimit a block of code in which exceptions could occur. • Immediately following the try block are zero or more catch handlers. Each catch specifies in parentheses an exception parameter representing the exception type the catch can handle.
10. IIf an exception parameter includes an optionalparameter name, the catch handler can use that parameter name to interact with a caught exception object.
11. There can be one parameterless catch handler that catches all exception types.
12. After the last catch handler, an optional finally block contains code that always executes, regardless of whether an exception occurs.
13. When a method called in a program or the CLR detects a problem, themethod or CLR throws an exception. The point in the program at which an exception occurs is called the throw point.
14. Exceptions are objects of classes that inherit directly or indirectly from class Exception.
15. C# uses the termination model of exception handling. If an exception occurs in a try block, the block expires and program control transfers to the first catch handler following the...
tracking img