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)
- Credit memo and debit nemo in AR and ap
- System calls
- Solenoid 12v valve work in DC voltage?
- Dynamic cache
- Difference between impicit index and explicit cursor
- Effective test cases
- Windows 2000 vs windows 2000 server
- O2c, p2p, r2r
- Preparing salary sheet
- Half controlled and full controlled rectifier
- Vpn and vlan
- Difference beetween ppc & opc
- Etl case and decode
- Inter-company journals
- Multiple test scenarios from one test case
- Teach new employee about personal information
- Non zero max.Code setting maxxcc=0
- Number system - single smallest possible square number
- Pre-emtive and non-pre-emtive scheduling
- Selenium framework architecture