Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Java in General (advanced)

Java in General (advanced) For really tough questions -

Exception handling


If I catch an exception in a try-catch block, it should go no further right?  I'm dealing with a method that's called from a method of another class.  Even if I catch the exception in the called method, the calling method's try-catch block is also invoked.Has anybody got an explanation for this?  I don't 'throws' the exception from the called method either.

   
   

   
   
      PaulCould the catch be throwing an exception?do you have code to post? or the error message?Dave

   
   

   
   
      Could the fact that I have the try-catch in the constructor be causing the problem?  The code is a little cumbersome so I'll give you a skinned down version.public class Class1{  public Class1()  {   try {     method1();     } catch (Exception ex) { //main catch   }  }public void method1() throws Exception {    MyObj mo = new MyObj(); }}public class MyObj{  public MyObj()  {    try {         errorMethod();    } catch (Exception ex) { //handle it here    }  }errorMethod() throws Exception  {     int y = 10/0;    // causes exception  }}I woudl expect the ArithmeticException to be completely handled in the constructor of MyObj.  Why is it also being caught by the constructor of Class1?Many thanks!

   
   
   
   
   
      Very strange.  I don't see how this could happen given the code you've posted.  Maybe I'm missing something, or maybe you've simplified out some important detail.  Is it possible that there are two exceptions from two different places?  Maybe you're catching one and stopping it, and subsequently another is thrown from another place?Wherever you're currently catching the exception, be sure to print out the somplete stack trace and study it carefully.  There should be line numbers along with method names, identifying exactly where it came from.  These are your most important clues.Also, realize that ArithmeticException is a RuntimeException.  Therefore it doesn't matter if you don't declare that a method "throws" it or not - it can appear anywhere you perform integer division.Good luck...

   
   

   
   
      You are dead right Jim.  There was another exception being thrown in the calling class.  It was caused by my ArithmeticException which prevented some other code being executed - but it was ultimately a different exception.Thanks for your help.I normally use ArithmeticExceptions when testing because they're so easy to generate.


Related Links

prevent 2 instances of same program
Compiling problem with generics.
extract .rar file with java
One implementation doubt
I'm getting a really weird IOException...
Tools required for changing byte-code
Parsing M*N matrix on Periphery
Regarding date conversion
ClassCastException
BIRT
get fifth element from last linked list
SAP Integration - Required some guidance
Variable increment problem (threads)
How to make text field to accept only alphabets
How can I get....
why interface