Week 4 DQ 1 Write a short essay in which you discuss the different program error
ID: 3547753 • Letter: W
Question
Week 4 DQ 1
Write a short essay in which you discuss the different program errors that are likely to occur and how they should be handled within scripts.
Week 4 DQ 2
Write a 200- to 300-word response that discusses the different reasons for terminating a process and the commands used for this purpose.
Week 4 DQ 3
Compare and contrast using the command line versus a graphical user interface (GUI) for systems administration functions. What are the advantages and disadvantages of each?
Week 4 DQ 4
What are the advantages and disadvantages to the large number of Linux
Explanation / Answer
There are three types of errors in programming: (a) Syntax Errors and (b) Runtime Errors (c) Logical Errors:
Syntax errors, also called parsing errors, occur at compile time for traditional programming languages and at interpret time for JavaScript.
For example, the following line causes a syntax error because it is missing a closing parenthesis:
When a syntax error occurs in JavaScript, only the code contained within the same thread as the syntax error is affected and code in other threads gets executed assuming nothing in them depends on the code containing the error.
Runtime errors, also called exceptions, occur during execution (after compilation/interpretation).
For example, the following line causes a run time error because here syntax is correct but at run time it is trying to call a non existed method:
Exceptions also affect the thread in which they occur, allowing other JavaScript threads to continue normal execution.
Logic errors can be the most difficult type of errors to track down. These errors are not the result of a syntax or runtime error. Instead, they occur when you make a mistake in the logic that drives your script and you do not get the result you expected.
You can not catch those errors, because it depends on your business requirement what type of logic you want to put in your program.
The latest versions of JavaScript added exception handling capabilities. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions.
You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.
Here is the try...catch...finally block syntax:
The try block must be followed by either exactly one catch block or one finally block (or one of both). When an exception occurs in the try block, the exception is placed in e and the catch block is executed. The optional finally block executes unconditionally after try/catch.
Here is one example where we are trying to call a non existing function this is causing an exception raise. Let us see how it behaves without with try...catch:
Now let us try to catch this exception using try...catch and display a user friendly message. You can also suppress this message, if you want to hide this error from a user.
You can use finally block which will always execute unconditionally after try/catch. Here is an example:
You can use throw statement to raise your built-in exceptions or your customized exceptions. Later these exceptions can be captured and you can take an appropriate action.
Following is the example showing usage of throw statement.
You can raise an exception in one function using a string, integer, Boolean or an object and then you can capture that exception either in the same function as we did above, or in other function using try...catch block.
The onerror event handler was the first feature to facilitate error handling for JavaScript. The error event is fired on the window object whenever an exception occurs on the page. Example:
The onerror event handler provides three pieces of information to identify the exact nature of the error:
Error message . The same message that the browser would display for the given error
URL . The file in which the error occurred
Line number . The line number in the given URL that caused the error
Here is the example to show how to extract this information
You can display extracted information in whatever way you think it is better.
You can use onerror method to show an error message in case there is any problem in loading an image as follows:
<script type="text/javascript"> <!-- window.print(; //--> </script>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.