Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exception Handling By: Enas Naffar.

Similar presentations


Presentation on theme: "Exception Handling By: Enas Naffar."— Presentation transcript:

1 Exception Handling By: Enas Naffar

2 Exceptions An Exception is a problem that takes place at the execution of a program (at runtime). Example: Division by zero

3 Code structure try {…..} catch // Possibly more than one catch { …}
finally {… }

4 Code structure  A try block contains the code that might holds an exception. A catch block is used to handle any resulting exceptions. A finally block contains the code that should always be executed. A try block requires one or more associated catch blocks, or a finally block, or both.

5 Exception examples FileNotFoundException FormatException
DivideByZeroException

6 Exception properties Some Exception properties: Message StackTrace
HelpLink

7 User-defined exceptions
A user-defined exception class should inherits from Exception class. public class myexecption : Exception It is preferred to provide (at least) the same constructors of the base class and passing the parameters to the base class constructors public myexecption(string m) : base(m) { }

8 In the try block, the programmer throws an exception.
{ ……… if (x == 1) throw (new myexecption(“invalid”)); }


Download ppt "Exception Handling By: Enas Naffar."

Similar presentations


Ads by Google