Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Exception  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ran into a run-time error while executing this code snippet:
class SomeThrowable extends Throwable { }
class MyThrowable extends SomeThrowable { }

public class TestException
{
public static void main(String args[]) throws SomeThrowable
{
try{
m1();
}catch(SomeThrowable e){
throw e;
}finally{
System.out.println("Done");
}
}
public static void m1() throws MyThrowable
{
throw new MyThrowable();
}
}
The run-time error is like this:
Exception in thread "main" MyThrowable
at TestException.m1(TestException.java:19)
at TestException.main(TestException.java:9)
This small program went through when I commented out the "throw e" which is within the catch block. Does it mean that throwing exception within a catch block will cause trouble?
Thanks
 
Gold Digger
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger,
your program is behaving correctly. The exception you see at runtime is the one you are explicitely throwing in the catch block (which is perfectly correct). I wonder what behavior you expected ? Does this answer your question ?
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!