The Artima Developer Community
Sponsored Link

Java Answers Forum
exception handling

2 replies on 1 page. Most recent reply: Jul 31, 2002 4:48 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Vanna Nguyen

Posts: 3
Nickname: vanilla
Registered: Jul, 2002

exception handling Posted: Jul 28, 2002 10:54 AM
Reply to this message Reply
Advertisement
explain the strange behavior of below method:
void strange() throws Exception {
try {
throw new Exception ("firstException");
}
finally {
System.out.println("finally is executed");
throw new Exception("second exception");
}
}


thomas

Posts: 42
Nickname: turbomanic
Registered: Jul, 2002

Re: exception handling Posted: Jul 28, 2002 11:21 AM
Reply to this message Reply
Dont throw an exception in the try statement. You must catch the exception in the catch statement and tell the computer what then to do with it.

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: exception handling Posted: Jul 31, 2002 4:48 PM
Reply to this message Reply
What don't you understand ?
  try 
  {
    System.out.println ("Before throwing an Exception");
    throw new Exception ("firstException");
  } finally 
  {
    System.out.println ("finally is executed");
    throw new Exception ("second exception");
  }

Running the code you should get :
Before throwing an Exception.
finally is executed

AFAIK only the first Exception should be visible, not the second.

Thomas SMETS,

Flat View: This topic has 2 replies on 1 page
Topic: applet to application Previous Topic   Next Topic Topic: policy file for applet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use