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 9259199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:35:50+00:00 2026-06-18T12:35:50+00:00

I encountered quite annoying problem. I can’t catch errors thrown from within the functions.

  • 0

I encountered quite annoying problem. I can’t catch errors thrown from within the functions. And to be honest – I wouldn’t care much if not the fact that the same applies for throwing errors from within the JavaScript Objects.

Here’s the sample code:

http://jsfiddle.net/TxsHK/1/ (you’ll need firebug console to test this code)

function ViewError($CONTENT){
    this.content = $CONTENT;

    return this.content;
};


try{
    $(document).ready(function() {
    //--------------
          throw ViewError('Test error');
    //--------------
    });//$(document).ready(function() {
}catch (e) {
    if (e instanceof ViewError) {
        console.info(e.message);
    }
    else{
        console.warn(e.message);
    }
}

gives an error

TypeError: e is undefined

Why? The errors thrown by functions (or objects) should be perfectly catchable. That’s the whole purpose of try – catch block: to catch exceptions out of functions. At least… so it is in other languages.

Anyone can explain what’s going on? And how can I catch exceptions from within the functions / objects?

  • 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-18T12:35:51+00:00Added an answer on June 18, 2026 at 12:35 pm

    Your “ViewError” function doesn’t return anything. You’re therefore throwing undefined. (edit — your fiddle is diffferent from the posted code – don’t do that!)

    The “ViewError” function is being called in a way that I don’t think to be correct, given the way the code is written. I think you want throw new ViewError("Test error"); in order to make sure a new object is created.

    There’s another problem: you’re expecting that you’ll be able to catch exceptions thrown from that call to $(document).ready(), but that’s not necessarily going to work. If the document isn’t ready yet when that code runs, then you’ll get no exceptions because the call returns immediately. The function you pass in would be called later, when the document is ready.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I run my site on IE8, I encountered quite a lot of errors:
The instanceof keyword in JavaScript can be quite confusing when it is first encountered,
i encountered a problem using the apache commons-net telnet api, and hope you can
I encountered a problem when I tried to use java from matlab. I read
I am new to ExtJS and I encountered a similar problem from Sencha forum
I have encountered a problem that I cannot quite figure out. Would be super
I encountered a behaviour I can´t quite understand when I was trying to populate
I've encountered a problem while trying to use the answer from a NDSolve in
It seems that this problem has already been encountered by quite a few people:
I'm quite new at WPF and recently encountered a problem. I got an ObservableCollection<

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.