SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: error object

  1. #1
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    error object

    Could someone explain these please

    PHP Code:

    function TryCatchDemo(x){
       try {
          try {
          if (
    == 0)   // Evalute argument.
             
    throw "x equals zero";   // Throw an error.
          
    else
             throw 
    "x does not equal zero";   // Throw a different error.
          
    }
          catch(
    e) {   // Handle "x = 0" errors here.
             
    if (== "x equals zero")   // Check for an error handled here.
                
    return(" handled locally.");   // Return object error message.
             
    else   // Can't handle error here.
                
    throw e;   // Rethrow the error for next
          
    }   // error handler.
       
    }
       catch(
    e) {   // Handle other errors here.
          
    return(" handled higher up.");   // Return error message.
       
    }
    }
    document.write(TryCatchDemo(0));
    document.write(TryCatchDemo(1)); 
    and

    PHP Code:

    try {
      print(
    "Outer try running..");
      try {
        print(
    "Nested try running...");
        throw 
    "an error";
      }
      catch(
    e) {
        print(
    "Nested catch caught " e);
        throw 
    " re-thrown";
      }
      
    finally {
        print(
    "Nested finally is running...");
      }   
    }
    catch(
    e) {
      print(
    "Outer catch caught " e);
    }
    finally {
      print(
    "Outer finally running");
    }
    // Change this for Windows Script Host to say WScript.Echo(s)
    function print(s){
       
    document.write(s); 
    whats WScript/finally?

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WSH

    Well, i've not got time to read through it all, so i scanned it and i'll comment on two things for you.

    try {
    }
    catch(e){
    }

    initiates a seperated (buffered) error cache for the duration of the said function. On the event of an error the handler of catch is used.

    e (event) has several properties, (all at msdn.microsoft.com/library)

    e.description, e.type etc.

    This is an alternative to using the window.onerror method ( which does have loopholes )


    Wscript is an object.
    The normal method for invocation is:

    var shl= new ActiveXObject("WScript.shell");
    shl.run("telnet.exe www.test.org");

    This will invoke the WSH (windows script host) which has a lot of very powerful applications.
    Unfortunately it is used mainly for virii now-a-days.

    Hope this helps you
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for that would you also mind explain,

    finally

    &

    throw.


    where did you read up on these, as I would like to find out more about these types of things.

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Throw Statement:

    Generates an error condition that can be handled by a try...catch…finally statement.

    Try loop:

    try {
    tryStatements}
    catch(exception){
    catchStatements}
    finally {
    finallyStatements}


    tryStatements
    Required. Statements where an error can occur.

    exception
    Required. Any variable name. The initial value of exception is the value of the thrown error.

    catchStatements
    Optional. Statements to handle errors occurring in the associated tryStatements.

    finallyStatements
    Optional. Statements that are unconditionally executed after all other error processing has occurred.


    I learnt by working with Jscript / Javascript and developing 3d interactive environments for activeX / direct animation.

    most of what you need is at:
    msdn.microsoft.com/library

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice, so do you have any examples that I would realistically use in a website?

    So I can get an Idea of when and where to use them.

    thanks again

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confidential work

    Most of my work is development for large companies which like to keep the fact they outsource some development very private.

    In general the use of try, catch and throw would be limited.
    If you're mehtods/functions are websafe, well then you don't really ever need this.

    The occassion when you would, is when you are planning on doing something that could well fall over.
    eg.. trying to read a file off the hard disk where the file could be in one of several locations.
    You'd embed another try into each of the catches and then in the final catch, do something to handle the whole lot.

    try {
    regread('\\path\\key');
    }
    catch(e){
    if (e.description == "not valid key"){
    try {
    regread('\\path2\\key')'
    }
    catch(e){
    if (e.desc....
    ....
    }
    }
    else {
    dhandleError();
    }
    }

    now before you ask... NO, i'm not giving you the function to read the registry.
    If you want to find it i think i posted a clue to it in another thread today.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, I'm surprised this is possible with javascript, although it asks for an active x dont it, or does it give a warning any you've been a great help thanks for this.

  8. #8
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The power you're given

    Well with WSH javascript can achieve pretty much anything.
    If you know how to invoke a WSH without activeX handlers being called (normally by abusing trusted windows clssid's for an object) then you can do whatever you want.
    You should have no problem downloading a file without prompting, renaming files, or ever formating without prompting.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •