Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution.


Try-catch is a syntactic construct for catching exceptions raised by a code section


Quality Example

"Will hide the exception-handling and since dealing with exception-handling is heavier compared to a simple if t why isn t the normal new t not considered less good practice considering we will have to use try-catch to check if a simple allocation succeeded and if we don t just watch the program die"

from question "Nothrow or exception?"


"So here the unchecked exception-handling is better to use in order not to copy and paste all that ugly try-catch block rethrowing an exception-handling and add the throws clause to the method"

from question "How am I supposed to let an Unchecked Exception bubble up and log?"

"When you call input.nextline as part of your exception-handling catching is it better to place it into every catch block or just inside a finally block at the end of the try-catch"

from question "Java Exception Handling for Scanner input: Clearing bad data with nextLine (catch vs Finally)"


"Try-catch rsources is fine for some cases but this is the old way and works better when you have more than 1 exception-handling in a block"

from question "Why does my code create a .txt file, but doesn't write information in it?"

"In general try-catch is more robust does not require you to define an exact position of where to test could be a block and provides info about the exception-handling"

from question "Why use Try/Catch instead of testing for an NSError"

Actually slower

"Try-catch is actually slower if there really is an exception-handling thrown"

from question "Can try catch be used for code optimization?"

Back to Home
Data comes from Stack Exchange with CC-BY-SA-3.0