Find jobs - Lyrics - Debt Consolidation - US Business Directory - Watch Anime

PDA

View Full Version : Difference between Error & Exception


ltimranjaved
Apr 28th 2009, 10:33 am
During doing some work in java a question came into in my mind that Are both same ? or are they different?

So i decided to take yours input.

In my thinking anything which can be handled or can be imagined before it occurs in java we call it exception otherwise its an error?

Am i Right?

ltimranjaved
Apr 29th 2009, 1:51 am
no one agreed or disagreed yet

dimitar christoff
Apr 29th 2009, 4:47 pm
i believe you are essentially correct - despite of my limited grasp on the subject.
"exceptions" refers to errors (runtime) that can be trapped and controlled. as opposed to "errors" that are just bad syntax and break the compiler fully...

for instance, this is an exception which is being handled:
try {
colours[2] = "red";
} catch (e) {
alert("Oops!"); // assignment failed because colours is not in the global namespace as an array
}

whereas this:

alert("the quick brown fox jumps over the lazy dog);
is a syntax error (missing ").

another thing you can is you can figure and log the exceptions - do a console.log(e) to see the properties, i believe something like e.message, e.name etc. you can also check against error types like:

if (e instanceof TypeError) ... or just ignore exceptions and do nothing at all.

dimitar christoff
Apr 29th 2009, 6:52 pm
i just remembered I had planned to post my exceptions handler and reporting tool (via ajax) on my blog for a while, thanks :D it's public now...

if interested in the idea of knowing about your visitors' javascript exceptions, click here:
http://fragged.org/obscure-javascript-exception-trapping-and-reporting-via-ajax-for-mootools_512.html

ltimranjaved
May 1st 2009, 8:07 am
i just remembered I had planned to post my exceptions handler and reporting tool (via ajax) on my blog for a while, thanks :D it's public now...

if interested in the idea of knowing about your visitors' javascript exceptions, click here:
http://fragged.org/obscure-javascript-exception-trapping-and-reporting-via-ajax-for-mootools_512.html

you have done a great effort,i liked it.
keep it up

gironaairport
Sep 13th 2009, 10:05 am
i believe you are essentially correct - despite of my limited grasp on the subject.
"exceptions" refers to errors (runtime) that can be trapped and controlled. as opposed to "errors" that are just bad syntax and break the compiler fully...

for instance, this is an exception which is being handled:
try {
colours[2] = "red";
} catch (e) {
alert("Oops!"); // assignment failed because colours is not in the global namespace as an array
}

whereas this:

alert("the quick brown fox jumps over the lazy dog);
is a syntax error (missing ").

another thing you can is you can figure and log the exceptions - do a console.log(e) to see the properties, i believe something like e.message, e.name etc. you can also check against error types like:

if (e instanceof TypeError) ... or just ignore exceptions and do nothing at all.

great answer