Error Handling in JAVA

There are two types of errors in JAVA. Run-time error and Logic error.
Runtime errors - are errors that pop outs while you are using or running your program. A program crash!
Logic errors - are errors in your program logic. Like an infinite loop.
Syntax errors - are errors in your code syntax. In NetBeans, it is underlined automatically by red line.


The try catch statement:
try {
    //your code here
}
catch ( Type_of_Exception variable_for_error ) {
    //Do something with the error here
}

In the try {} code block, it is where your code that you want to test/try. If there are errors, it will automatically catch the error in the catch{} code block. Java uses the default exception type if you don't placed the correct Type_of_Exception.

Learn from this code:
try catch block in java


Comments and Questions are well accepted! Thanks!

No comments:

Post a Comment