Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class L1 extends Exception
- {
- public String toString()
- {
- return "L1";
- }
- }
- class L2 extends Exception
- {
- public String toString()
- {
- return "L2";
- }
- }
- class Test
- {
- public static void main(String[] args)
- {
- try //fct pana la prima exceptie (i==0)
- {
- for (int i=0; i<4; i++)
- {
- if(i==1)
- throw new L1();
- else
- throw new L2();
- }
- }
- catch (L1 e) //prinde prima exceptie care sare, e = referinta locala
- {
- System.out.println(e);
- }
- catch(L2 e)
- {
- System.out.println(e);
- }
- //sau echivalent:
- catch (Exception e) //prinde prima exceptie care sare, e = referinta locala
- {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement