Class Running Notes 1st Nov
Class Running Notes 1st Nov
Dt : 1/11/2022
*imp
class.
step-5 : when Exception Condition is true then create object for User
creation process.
step-6 : Use "throw" keyword and throw the object reference onto catch
block.
Ex-program :
IComparable.java
package test;
public interface IComparable {
public abstract int compare(int x,int y);
}
DemoException1.java(MainClass)
package maccess;
import test.*;
import java.util.*;
super(msg);
try
if(v1==v2)//Exception Condition
System.out.println("====Choice====");
System.out.println("1.GreaterValue\n2.SmallerValue");
case 1:
if(x>y) return x;
else return y;
};
int r1 = gv.compare(v1,v2);
System.out.println("GreaterValue:"+r1);
break;
case 2:
if(x<y) return x;
else return y;
};
int r2 = sv.compare(v1,v2);
System.out.println("SmallerValue:"+r2);
break;
default:
System.out.println("Invalid Choice...");
}//end of switch
}//end of try
System.out.println(de.getMessage());
}
finally
s.close();
=================================================================
Diagram:
=================================================================
Ex-program:
Note:
=>EmpDesg must be in SE or TE or ME
package test;
public class Designation {
public boolean verify(String desg) {
return switch(desg) {
case "SE":yield true;
case "TE":yield true;
case "ME":yield true;
default : yield false;
};
}
}
DemoMethods2.java(MainClass)
package maccess;
import java.util.*;
import test.Designation;
super(msg);
try
throw de;
boolean k = dg.verify(desg);
if(!k)//Exception Condition
throw de;
if(bSal<12000)//Exception condition
throw de;
System.out.println("EmpId:"+eId);
System.out.println("EmpName:"+eName);
System.out.println("EmpDesg:"+desg);
System.out.println("EmpBSal:"+bSal);
System.out.println("EmpTotSal:"+totSal);
}//end of try
catch(DemoException2 de)
System.out.println(de.getMessage());
catch(InputMismatchException ime)
finally
s.close();
}
=================================================================
Assignment:
================================================================
*imp
define "Throwable"?
1.Error class
2.Exception class
===================================================================