An introduction about data class and exception class

Posted this to make aware by the term data class and exception class


First of all it is necessary to know that what is data class and what is exception class 
data class is generally hat we write that is what the the programmer or the user write.

So i would like to make the clear difference about it.

First to understand it we have to  the word throw and return  return comes into picture when the question comes about calling the function in the class specified by the user think that the user constructed the class A in which the methods are defined such as for e.g add(); ,sub();,test(int a,int,b);  so from the  main  user calls it explicitly by passing the argument or without argument

So if the function contains any return type and returns the statement then it gets return where the calling statement is specified

So this is the concept about how the function works by calling and returning the value of from where it is called.

 Now about the word throw: 

Throw word comes into the picture when exception is generated normally when exception is generated it is thrown where the user inputs the values for example if  a/b By mistake when the user inputs the value of b =0, divide by zero exception is generated and  this message is thrown on to the user screen or and editor from where the user inputs the values that is for C editor has been provided so this message of exception is thrown on the editor for JAVA we provide the values  from command prompt

for throwing the exception it is not in the hand of user in run-time if exception is generated the message is thrown automatically. And comes the  abnormal end  of the program. 

To understand the logical and abnormal end is explained in the previous post

  • It is necessary that user should bring logical End that is the statements after exception should also be executed for that we need a catch  statements which would catch the exception generated at run-time.
  • Normally when the exception is generated it dose't check for the catch statements and always throw the message on the user screen and the statements after exception is not executed.      
  • So to declare that we have kept catch statements we need to write the key-word try this indicates that somewhere down the code the user kept the catch statements.
  • For catch statements it must consists of the parameter that should match the exception type of object.  
  • For example if we think our exception is caught then the statements after it is executed normally and brings the logical end.

Now coming back to our topic Data-class and Exception Class:

  • Data class is the class which is defined by the user that means we create a normal class.
  • This class does't allows us to put the throw key-word.

throw calls catch so when we write  throw in a try block its catch statements is necessary. If catch does't provided, gives an Error. 

After the exception thrown by throw key-word and caught by catch key-word then the control does't return anywhere, In fact proceeds towards the logical end. So that is the main difference between the word throw and return.

throw is not returned as it is not called from anywhere but the case is different with the keyword return so the difference between the class data and exception is that with the data class we can use only the word return but not throw  but in the exception class we cannot use the word return as in place of throw .

Generally JAVA provides the exception class and the sub class are derived from it such as arithmetic exception, array index out of bound etc.

They are derived as the method of how to throw the exception and what all process is done is defined there.


So this was the concept behind the differentiation between the data class and the exception class...








  
  

Comments

Popular posts from this blog

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Navigation in Vaadin.

Drag and drop items from one Grid to another