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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:56:34+00:00 2026-05-14T01:56:34+00:00

I don’t think that this is doable, but wanted to throw it out to

  • 0

I don’t think that this is doable, but wanted to throw it out to the community to confirm my suspicions.

Let’s say you’re writing a program in another language like Python, PHP, or ASP. This program is intended to build another program written in JavaScript. However, the first program is unfortunately not immune to errors. So, occasionally, the program which builds the JavaScript program does some funky stuff and outputs a syntax error in the JavaScript source. Now some user goes and loads the program and it essentially halts, because the web browser running it can’t properly parse the JavaScript. This user is probably not going to be happy. I wouldn’t be.

This brings me to my question. Is it possible to write an error handler that would catch these kind of syntax problems allowing the application to fail gracefully?

Here’s an example:

    <html>
  <head>
   <script type="text/javascript" charset="utf-8">
    window.onerror = errorHandler;
    function errorHandler(a,b,c) {
     alert('horray!  No wait, Booo!');
    }
    vara jfs;
   </script>
  </head>
  <body>
   Can this be done?
  </body>
 </html>

or

<html>
  <head>
   <script type="text/javascript" charset="utf-8">
    try {
     vara jfs;
    } catch  (e) {
     alert('horray!  No wait, Booo!');
    }
   </script>
  </head>
  <body>
   Can this be done?
  </body>
 </html>
  • 1 1 Answer
  • 1 View
  • 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-05-14T01:56:34+00:00Added an answer on May 14, 2026 at 1:56 am

    Generally, a programming language is parsed, and if that succeeds possibly compiled to another form, and if that succeeds then interpreted/executed on hardware or a vm. Just because code passes one phase, doesn’t mean it’s valid code.

    You are asking if code running in the last phase, can be aware of problems encountered in the first part and deal with it.

    Some languages offer various hooks into it’s own parsing and compiling mechanism. As Cheeso mentioned, eval is Javascript’s way of calling into this mechanism.

    Rather than wrapping all of your scripts in strings, it might be nicer to leave them in javascript files, and load them into your main program with the following javascript (or similar).

     function load(file){
        var client = new XMLHttpRequest();
        client.open("GET", file, false);
        client.send(null);
        return client.responseText;
      }
    
      function include(file){
        try {
          eval(load(file));
        } catch (e) {
           alert("problem with file " + file);
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't think this is particularly quirky, but in an attempt to control my
I don't know whether this is really possible, but I'm trying my best. If
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't think that I'm mad, I understand how php works! That being said. I
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know why this is happening, but after submitting a form via JS (using
Don't know if this is an eclipse specific problem but whenever I declare a
DON'T ASK WHY but... I have a regex that needs to be case insensitive

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.