1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Difference between Error & Exception

Discussion in 'JavaScript' started by ltimranjaved, Apr 28, 2009.

  1. #1
    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 28, 2009 IP
  2. ltimranjaved

    ltimranjaved Peon

    Messages:
    254
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    no one agreed or disagreed yet
     
    ltimranjaved, Apr 29, 2009 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    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
    }
    PHP:
    whereas this:
    
    alert("the quick brown fox jumps over the lazy dog); 
    
    PHP:
    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 29, 2009 IP
  4. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #4
    dimitar christoff, Apr 29, 2009 IP
  5. ltimranjaved

    ltimranjaved Peon

    Messages:
    254
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ltimranjaved, May 1, 2009 IP
  6. gironaairport

    gironaairport Peon

    Messages:
    59
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    great answer
     
    gironaairport, Sep 13, 2009 IP