Ask Experts Questions for FREE Help !
Ask
    kishorekumar's Avatar
    kishorekumar Posts: 21, Reputation: 1
    New Member
     
    #1

    Oct 26, 2006, 02:08 AM
    Exceptions in java
    HI,
    I have a java class in which an exception occurred. Now the problem is I have to know from which class and from which method the exception is thrown.
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #2

    Oct 30, 2006, 10:07 AM
    Well you normally just have to look at the stack trace and this will tell you where it is thrown. Here's an example:

    Code:
    try {
      // The below throws an exception
      MyClass.doSomething();
    } catch (Exception e) {
      System.err.println("Error: "+ e.getMessage());
      e.printStackTrace();
    }
    This will print out something like the following when an error is thrown:
    Code:
    Error: null
    java.lang.NullPointerException
        at com.myPackage.test.java:25)
        at com.myPackage.test.java:18)
        at com.myPackage.test.java:14)
    The "at com.myPackage.test.java" part is the class that threw the error. The number following the colon is the line error the error was thrown on.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java [ 3 Answers ]

Please will you help me with these questions... where can I find a great site that will help me answer these... 1/ Who developed Java and when? 2/ What are some unique features of Java? 3/ Is java used for websites or stand alone programs? 4/ What does it mean when I say java is an "object...

Java Is used for [ 2 Answers ]

When I rest my pointer over a link, it diplays information about that link Is that Java at work? Why are there different Jav versions? Is Java compiled like C or interpeted like Basic? Is this contained in Internet Explorer? Thank You very much

Java! [ 2 Answers ]

Please will you help me with these questions... where can I find a great site that will help me answer these... 1/ Who developed Java and when? 2/ What are some unique features of Java? 3/ Is java used for websites or stand alone programs? 4/ What does it mean when I say java is an "object...

By using vc++ or java? [ 1 Answers ]

Hi, I want to make image processing application.which programming language I should use? Either vc++ or java or anything else? Please guide me early.

Java Help! [ 1 Answers ]

Hi Experts, I'm not sure if I'm posting this in the right category, but I sure hope someone can still help me. I'm not able to view Java applets. I've downloaded the most recent version of JVM. I have version 1.4.1. I've tried changing some settings (like enabling Java in my internet...


View more questions Search