Exception - meaningless exception message
Guys please help
Whats with this code
import java.util.*;
publicclass ExcInMap{
static Map m;
publicstaticvoid main(String args[])throws Exception{
m =new HashMap();
m.put("st",new FancyException());
dummyCall();
}
staticvoid dummyCall()throws Exception{
Exception e =new FancyException();
throw (Exception)m.get("st");
}
}
class FancyExceptionextends Exception{
public String tostring(){
return"fancy became fantacy";
}
}
Output
Exception in thread "main" FancyException
at ExcInMap.main(ExcInMap.java:6)
I am wondering why from line 6 it shud be from line 11
Thanks in advance !
SanX
[1732 byte] By [
SanXa] at [2007-10-2 16:57:22]

> I am wondering why from line 6 it shud be from line
> 11
>
> Thanks in advance !
> SanX
Because the stack trace information is put into the exception when it is created. So it has line 6. If you change dummyCall() to the following, you will get what you expect.Exception e = (Exception)m.get("st");
e.fillInStackTrace();
throw e;
> btw Do you see why did they code so, my friendz
> dz will be curious! It shud have been from the place
> of throw?
>
> SanX
I suppose it could have been designed such that the 'throw' automatically called fillInStackTrace(). In the code I have written and seen, a new Exception has always been created at the point where it is thrown. So there may be few times when an Exception needs to be created before it is thrown and it isn't worth the extra work to make 'throw' call fillInStackTrace().