java - Can an Error be handled in the same way as an Exception -


i want know whether error can handled or not in java in similar way exceptions. have seen errors can't handled such assertionerror , i've tried throwing error inside program , tried handling using catch, worked , next part of code did execute(this contradictory part program supposed exited whenever error encountered). few errors can handled , few others cannot be. i'm confused this, can clear doubt of mine , state difference between errors , exceptions?

package package1;  public class class1  {    public static void main(string[] args) {     class1 cl1=new class1();     int x=2;     string s = null;     //assert(x<0):"x not less zero";     try     {         cl1.workonexceptions();     }     catch (error e)          {         e.printstacktrace();     }     system.out.println("not terminated yet"); } public void workonexceptions() throws error  {                                                    try                                              {         throw new exception("exception");     }     catch (exception e)      {         throw new error("exception again");         } } } 

some background on error: it's not intended catchable; comes when something goes really wrong. exception meant caught , handled, since it's may come on occasion, shouldn't interrupt or interfere severely running of program, such dividing zero.

as working inside of try...catch statement, reason property of throwable class.

only objects instances of class (or 1 of subclasses) thrown java virtual machine or can thrown java throw statement. similarly, class or 1 of subclasses can argument type in catch clause.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -