term1 Definition1term2 Definition2term3 Definition3
Please sign in to your Google account to access your documents:
Name two subclasses of arithmetic exception
OverflowException
DivideByZeroException
What are two common properties for all exceptions?
Message: gets a message that briefly describes the exception
StackTrace: gets a string that lists the methods that were called before the exception occurred
Common method for all exceptions
GetType()
Gets the type of the current exception
Display a dialog that shows the type of the exception in the title bar and then in the middle displays a brief description and the call stack
catch(Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Exception: " + ex.GetType.ToString());
}
Show syntax for try-catch-finally that catches multiple exceptions
try{...}
catch(ArithmeticException ex){...}
catch(DivideByZeroException ex){...}
catch(Exception ex){...}
finally{//do a thing}
syntax for throwing a new exception
throw new ExceptionClass([message]);
//the message is assigned to the Message property
syntax for throwing an existing exception
throw exceptionName;
catch(FormatException ex)
//do stuff
throw ex
When should you throw an exception?
-When a method encounters a situation where it cannot complete its task
-When you want to generate an exception to test an exception handler
-When you want to catch the exception, perform some processing, and then throw the exception again
Need help typing ? See our FAQ (opens in new window)
Please sign in to create this set. We'll bring you back here when you are done.
Discard Changes Sign in
Please sign in to add to folders.
Sign in
Don't have an account? Sign Up »
You have created 2 folders. Please upgrade to Cram Premium to create hundreds of folders!