MULTIPLE CATCH STATEMENT

No comments

It  is  possible  to  have  more  than  one  catch  statement   in  the  catch  block  as  illustrated  bellow.

try
{
     Statement;
     }
catch(Exception   type1   e)
{
   statement ;//process  exception  type1
-----------------------------------
------------------------------------
}
Catch(Exception  type2  e)
{
       Statement;//process  exception  type2
         }
.
.
.
.
catch (Exception  type_N  e)
{
     Statement;//process  exception  type  N.
       }
----------------------------------
----------------------------------
----------------------------------


When  an  exception  in  a  try  block  is  generated  ,  the  java  treats  the  multiple  catch  statement like  cases  in  a  switch  statement.  The  first  statement  whose  parameter  matches  with  the  exception  object  and  the  remaining  statement  will  skipped.

The  catch  statement  simply end  with  a  semicolon.  This  statement  catch  and  exception  than  ignore  it.

No comments :

Post a Comment

Subscribe

Milan Panda
Admin
About Me | Contact
Copyright 2023-2024 © Programming1011 . 🎀 Developed and Design By- Milan Panda. Happy Holi All Of You 🎀