What is the difference between throw and throws clause, explain in programatically
Editorial / Best Answer
Answered by: sri
throw is used to throw an exception manually, where as throws is used in the case of checked exceptions, to reintimate the compiler that we have handled the exception. so throws is to be used at the time of defining a method and also at the time of calling that function, which rises an checked exception.
Prog. to explain diff. b/w throw and throw:
class MyException extends Exception //to create our own exception
public String toString() //overriding the method toString() to print the desired msg.
return "Can not divide a no. with one: "+"MyException";
public static void main(String args) throws MyException //use of throws
throw new MyException(); // rises an MyException, if we try to divide a no. with 1
if we want to rise our own exception, we have to use either throws or to handle the exception by try-catch. if not, it gives the compile time error.
and throw is to rise the exception manually, In the above prog. I rised an exception when you try to divide a no with 1.(own Exception)
- What is difference between ipv4 & ipv6?
- How to convert multiple rows into single row in datastage
- Multiple database access one instance
- What is the difference between unearned revenue and unbilled receivables?
- How do you optimise your PL/SQL code?
- Exploratory testing
- Difference between is and as in Oracle
- Explain performance bottlenecks
- Please explain the relationships in hibernate
- Array differences
- What is the difference between pinion and gear
- What can be the side effects of using automation tools while testing ?
- Application support
- What is difference between tcp and udp and which is preferable
- Controlled and uncontrolled redundancy
- Explain about cross functional audits
- Memory addressing
- What is the difference between sequence diagram and collaboration diagram?
- What is the difference between disaster recovery at the data link layer and the transport layer?
- I have done project employee maintenance detail and they ask the program for main menu any one know the program of main menu if any one knows plzz explain.