Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9241469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:22:39+00:00 2026-06-18T08:22:39+00:00

in JS, you can throw a new Error(message), but if you want to detect

  • 0

in JS, you can throw a “new Error(message)”, but if you want to detect the type of the exception and do something different with the message, it is not so easy.

This post: http://www.nczonline.net/blog/2009/03/10/the-art-of-throwing-javascript-errors-part-2/

Is saying you can do it something like this:

function MyError(message){
  this.message=messsage;
  this.name="MyError";
  this.poo="poo";
}
MyError.prototype = new Error();

try{
  alert("hello hal");
  throw new MyError("wibble");
} catch (er) {
  alert (er.poo);   // undefined.
  alert (er instanceof MyError);  // false
      alert (er.name);  // ReferenceError.
}

But it does not work (get “undefined” and false)

Is this even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:22:40+00:00Added an answer on June 18, 2026 at 8:22 am

    Douglas Crockford recommends throwing errors like this:

    throw{
    
        name: "SomeErrorName", 
        message: "This is the error message", 
        poo: "this is poo?"
    
    }
    

    And then you can easily say :

    try {
        throw{
    
            name: "SomeErrorName", 
            message: "This is the error message", 
            poo: "this is poo?"
    
        }
    
    }
    catch(e){
        //prints "this is poo?"
        console.log(e.poo)
    }
    

    If you really want to use the MyError Function approach it should probably look like this :

    function MyError(message){
    
        var message = message;
        var name = "MyError";
        var poo = "poo";
    
        return{
    
            message: message, 
            name: name, 
            poo: poo
        }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can the new operator throw an exception in real life? And if so, do
As Error and Exception are subclass of throwable class, we can throw any error,
As title says, i know that new throws an exception which can be caught,
Can I throw an exception on the SQL 2005 server so that I can
I noticed that you can't throw an exception in a destructor. So my question
Ok, I've been told this problem: Why can you throw a pointer to a
In C#, I can use the throw; statement to rethrow an exception while preserving
I can't find out why throw this expression always a NullPointerException: String jpql =
I want to use Application_Error with my MVC project, but i can't get it
I think this isn't supposed to happen, but I can't find why this isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.