Tuesday, July 14, 2009

I am learning java application ..without giving exception my prg is giving error..i want to know some thing?

package javaexception;


class App {


public static void main(String args[]) {


a();


}


static void a() {


b();


}


static void b() {


c();


}


static void c() {


d();


}


static void d() {


int i = 1;


int j = 0;


System.out.println(i / j);


}


}


is my program...


java.lang.ArithmeticException: / by zero





at javaexception.App.d(App.java:36)





at javaexception.App.c(App.java:29)





at javaexception.App.b(App.java:24)





at javaexception.App.a(App.java:18)





at javaexception.App.main(App.java:13)


is the exception error...


what is my doubt is ..


App is my program name,,


(App.java:29)





(App.java:24)





(App.java:18)





(App.java:13)


what does the numbers 18,13 etc means

I am learning java application ..without giving exception my prg is giving error..i want to know some thing?
may be the line numbers of your coding
Reply:Firstly, I hope you understand the error was given because you are dividing a number, 1 in this case, by 0. This will always an exception.





Secondly, the numbers that are given out is a dump of the stack.





The stack basically holds the path that was taken to get to the exception, then when the exception happens, it produces what is called a stack trace.





You can trace the exception back through this stack to find out where the exception was called from in your program, etc. I hope that did not confuse you.





Basically, you stack trace reads as such,





The exception called ArithmeticException is thrown at line 36 of your App program.





Line 29 called the method the method that threw the exception, I presume it is the line the says 'd();'





Line 24 called the 'c' method, 'c();'.





Line 18 called the 'b' method, 'b();'.





Line 13 called the 'a' method, 'a();'.








Therefore, you can see the program worked correctly,





main called a, a called b, b called c, c called d, d threw the exception.
Reply:siscuss @ http://www.studyjava.org
Reply:It means exception raised at 29 (i/j)... here u r not handling exceptions so its thrown to its caller functiion (c())... 24 is line no of d(); in c() function.


like 18 and 13 are c(); and b();.........


No comments:

Post a Comment