JavaScript Throw Statement
The throw statement allows you to create an
exception.
Examples
The throw statement
How to use the throw statement.
The Throw Statement
The throw statement allows you to create an exception. If you use this
statement together with the try...catch statement, you can control program
flow and generate accurate error messages.
Syntax
The exception can be a string, integer, Boolean or an object.
Note that throw is written in lowercase letters. Using uppercase
letters will generate a JavaScript error!
Example 1
The example below determines the value of a variable called x. If the value
of x is higher than 10 or lower than 0 we are going to throw an error. The error is then caught by the catch argument and the proper
error message is displayed:
<html>
<body>
<script type="text/javascript">
var x=prompt("Enter a number between 0 and 10:","");
try
{
if(x>10)
throw "Err1";
else if(x<0)
throw "Err2";
}
catch(er)
{
if(er=="Err1")
alert("Error! The value is too high");
if(er == "Err2")
alert("Error! The value is too low");
}
</script>
</body>
</html>
|
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
|