5
1.What is an Exception? Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileNotFondException. Q2.What is the purpose of Exception Handling? Ans.The main purpose of Exception Handling is for graceful termination of the program. Q3.What is the meaning of Exception Handling? Ans. Exception Handling doesn’t mean repairing an Exception, we have to define alternative way to continue rest of the code normally. Example: If our programming requirement is to read the data from the file locating at London but at Runtime if London file is not available then we have to use local file alternatively to continue rest of program normally. This is nothing but Exception Handling. Q4.Explain Default Exception Handling Mechanism in java? Ans.If an exception raised, the method in which it’s raised is responsible for the creation of Exceptions object by including the following information: Name of the Exception Description of the Exception Stack Trace After creating Exception object the method handover it to the JVM. JVM checks for Exception Handling code in that method. If the method doesn’t contain any Exception handling code then JVM terminates the method abnormally and removes the corresponding entry from the stack. JVM identify the caller method and checks for Exception Handling code in that method. If the caller doesn’t contain any exception handling code then JVM terminates that method abnormally and removes the corresponding entry from the stack. This process will be continue until main() method.

EXCEpS@THRDS

  • Upload
    phani

  • View
    212

  • Download
    0

Embed Size (px)

DESCRIPTION

thrds

Citation preview

1.What is an Exception?Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileotFondException. !".What is the purpose of Exception #andling?Ans.$he main purpose of Exception #andling is for graceful termination of the program.!%.What is the meaning of Exception #andling?Ans. Exception #andling doesn&t mean repairing an Exception, we have to define alternative wa' to continue rest of the code normall'.Example: (f our programming re)uirement is to read the data from the file locating at *ondon butat +untime if *ondon file is not available then we have to use local file alternativel' to continue rest of program normall'. $his is nothing but Exception #andling.!,.Explain -efault Exception #andling .echanism in /ava?Ans.(f an exception raised, the method in which it&s raised is responsible for the creation of Exceptions ob/ect b' including the following information: ame of the Exception -escription of the Exception 0tac1 $race After creating Exception ob/ect the method handover it to the 23.. 23. chec1s for Exception #andling code in that method. (f the method doesn&t contain an' Exception handling code then 23. terminates the method abnormall' and removes the corresponding entr' from the stac1. 23. identif' the caller method and chec1s for Exception #andling code in that method. (f the caller doesn&t contain an' exception handling code then 23. terminates that method abnormall' and removes the corresponding entr' from the stac1. $his process will be continue until main45 method. (f the main45 method also doesn&t contain exception handling code the 23. terminates that main45 method and removes the corresponding entr' from the stac1. 2ust before terminating the program abnormall' 23. handovers the responsibilit' of exception handling to the -efault Exception #andler which is the component of 23.. -efault Exception #andler /ust print exception information to the consol in the following formatame of Exception: -escription0tac1 $race 4*ocation of the Exception5!6.What is the purpose of tr'?Ans We should maintain all ris1' code inside the tr' bloc1.!7. What is the purpose of catch bloc1?Ans.We have to maintain all Exception #andling code inside the catch bloc1.!8.(s tr' with multiple catch bloc1 is possible?Ans. $he wa' of handling an exception is varied from exception to exception compulsor' we have to write a separate catch bloc1 for ever' exception. #ence tr' will multiple catch bloc1 is possible and it is recommended to use.Example: tr'9::+is1' code;catch4(