If you are not sure if the website you would like to visit is secure, you can verify it here. Enter the website address of the page and see parts of its content and the thumbnail images on this site. None (if any) dangerous scripts on the referenced page will be executed. Additionally, if the selected site contains subpages, you can verify it (review) in batches containing 5 pages.
favicon.ico: javascript-tutorial.com/error-handling/error-types-conditional-catching - Error types & conditional .

site address: javascript-tutorial.com/error-handling/error-types-conditional-catching redirected to: javascript-tutorial.com/error-handling/error-types-conditional-catching

site title: Error types & conditional catching - The complete JavaScript Tutorial

Our opinion (on Thursday 19 November 2026 6:39:39 UTC):

GREEN status (no comments) - no comments
After content analysis of this website we propose the following hashtags:



Meta tags:

Headings (most frequently used words):

javascript, error, types, the, for, web, conditional, catching, throwing, errors, objects, re, custom, summary, chapter, article, toc, about, getting, started, basics, control, structures, data, built, in, operators, functions, classes, handling, regular, expressions, general, bom, dom,

Text of the page (most frequently used words):
the (72), error (63), this (24), and (21), you (21), javascript (19), #errors (19), types (18), can (18), type (17), catch (16), with (16), #catching (15), for (15), try (14), bigint (14), message (13), introduction (12), throwing (12), conditional (11), value (11), our (11), function (11), example (10), rangeerror (10), let (9), how (9), that (9), your (8), informativerangeerror (8), alert (8), throw (8), which (8), own (7), custom (7), between (7), range (7), class (7), min (7), max (7), number (7), like (7), not (6), different (6), will (6), see (6), new (6), more (6), but (6), specific (6), zero (6), operator (6), operators (6), article (5), here (5), use (5), using (5), where (5), else (5), thrown (5), wrong (5), might (5), methods (5), finally (4), want (4), name (4), just (4), regular (4), object (4), now (4), dividebigints (4), instanceof (4), something (4), 10000000000042 (4), have (4), handling (4), when (4), based (4), generic (4), functions (4), tutorial (3), previous (3), problems (3), these (3), what (3), occur (3), within (3), valid (3), must (3), run (3), extends (3), constructor (3), super (3), parameters (3), then (3), values (3), pass (3), create (3), course (3), code (3), from (3), return (3), went (3), are (3), call (3), statement (3), other (3), match (3), about (3), web (3), expressions (3), has (2), into (2), language (2), list (2), next (2), they (2), enough (2), easily (2), built (2), differentiate (2), various (2), handle (2), summary (2), uncaught (2), outside (2), look (2), console (2), please (2), complete (2), notice (2), three (2), well (2), minimum (2), maximum (2), informative (2), original (2), show (2), give (2), saw (2), simply (2), sometimes (2), because (2), handled (2), last (2), block (2), occurred (2), also (2), only (2), rethrown (2), situations (2), technique (2), action (2), property (2), actually (2), even (2), distinguish (2), one (2), problem (2), properties (2), discuss (2), chapter (2), talked (2), asp (2), net (2), dom (2), window (2), bom (2), search (2), fields (2), inheritance (2), getters (2), setters (2), prototypes (2), objects (2), array (2), basics (2), loops (2), toc (2), localization, suggest, correction, contact, com, 2007, 2026, been, fully, translated, following, languages, preferred, help, translate, click, czech, comes, build, both, optionally, don, place, entering, desired, prompt, enter, thank, was, accepts, actual, entered, user, generate, much, keyword, works, going, accept, creating, quite, easy, instantiate, along, specialized, generates, display, received, demonstrate, customize, write, mixed, get, difference, turned, check, around, rangeerrors, added, line, needed, rethrow, exception, created, dividing, two, catches, any, case, occurs, isn, requires, some, combine, ability, words, responsibility, demonstrated, caller, precise, indication, consumer, perform, know, either, looking, its, comparing, utilizing, called, vary, depending, very, useful, dealing, complex, cases, several, instead, verify, division, full, currently, available, many, would, divide, reference, page, always, provide, least, describing, however, possibly, until, dealt, there, versions, becomes, especially, relevant, articles, blocks, could, ourselves, wpf, php5, jquery, html5, css3, webforms, mvc, location, history, script, tag, general, replace, capturing, groups, regex, flags, options, static, classes, extension, accessors, multiple, recursive, callback, anonymous, default, optional, chaining, nullish, coalescing, ternary, remainder, logical, modify, assign, increment, decrement, arithmetic, comparison, assignment, json, math, date, string, conversion, null, undefined, strings, numbers, booleans, data, while, switch, control, structures, truthy, falsy, variables, basic, syntax, hello, world, tools, need, getting, started, libraries, webbrowser, table, contents,


Text of the page (random words):
error types conditional catching the complete javascript tutorial javascript tutorial toc table of contents chapter article toc introduction catching errors try catch catching throwing errors try catch finally error types conditional catching error types conditional catching re throwing errors throwing custom errors summary about javascript what is javascript javascript and the webbrowser javascript libraries getting started the tools you need hello world the basics basic javascript syntax variables truthy falsy control structures the if statement the switch statement loops for and while loops for of and for in data types introduction booleans numbers strings null undefined type conversion built in objects introduction number string array the basics array methods date math json operators introduction the assignment operator comparison operators arithmetic operators increment decrement operators modify and assign operators logical operators remainder operator conditional ternary operator nullish coalescing operator optional chaining operator functions introduction function parameters function parameters with default values anonymous functions callback functions recursive functions multiple return values objects introduction properties methods property accessors getters setters prototypes prototypes inheritance extension classes introduction fields methods getters setters inheritance static fields methods error handling introduction catching errors try catch catching throwing errors try catch finally error types conditional catching regular expressions introduction regex flags options search match with regular expressions using capturing groups search replace with regular expressions javascript for web general introduction window dom bom the script tag javascript for web the bom the window object the history object the location object javascript for web the dom introduction javascript asp net mvc asp net webforms c css3 html5 jquery php5 wpf error handling error types conditional catching in the previous articles in this chapter we talked about how we can catch errors in javascript using try catch and try catch finally blocks we even talked about how we could throw errors ourselves until now we have dealt with the generic error type which errors in javascript are based on but actually there are more specific versions of a javascript error this becomes especially relevant when you want to distinguish between these different types of errors which we ll discuss in this article we ll also discuss how you can create your own error types for throwing specific errors to match the type of problem error types the generic error type will always provide you with at least a name and a message describing the problem however based on the error that occurred javascript might use a more specific error type based on the generic error type but possibly with more properties and or methods for a full list of the currently available error types please see this reference page for now let me show you one of the specific error types that javascript might throw the rangeerror it can occur in many different situations but one example would be if you try to divide a bigint with zero like this let bigint bigint 10000000000042 let zero bigint 0 alert bigint zero if you run the example you will see an error like this in your console uncaught rangeerror division by zero as you can see this is now a rangeerror instead of just the generic error type we can verify this when we catch the error and we can even use it to distinguish between other errors conditional catching by utilizing a technique called conditional catching we can actually vary our course of action depending on which type of error is thrown this can be very useful when dealing with more complex cases where several different types of errors might occur we know which type of error is thrown either by looking at its name property which will match the type of error or by comparing it to the specific type using the instanceof operator here s an example of how conditional catching might look try let bigint bigint 10000000000042 let zero bigint 0 alert bigint zero catch error if error instanceof rangeerror alert something is wrong with the range else alert something else went wrong notice how i can easily differentiate between the action i want to perform based on the type of error that is thrown re throwing errors in the last article i demonstrated how you can throw an error to give the caller of your code a precise indication of what went wrong but sometimes you only want to handle a specific type of error and let other types be handled by the consumer of your code function for situations like that we can combine the technique of conditional catching with the ability to throw errors from the catch statement in other words we can re throw an error to pass on the responsibility of handling the error here s an example function dividebigints b1 b2 try return b1 b2 catch error if error instanceof rangeerror alert something is wrong with the range else throw error dividebigints bigint 10000000000042 bigint 0 in this example i have created a function for dividing the two bigint s it catches any error but in case an error occurs which isn t a rangeerror the error is simply rethrown of course this requires that we do some error handling of our own when we call the function to see the difference in this next example i have turned the error check around so that only rangeerrors are rethrown and then i have added a try catch block for the line where we call the function this is needed because we call a function that might rethrow an exception i also demonstrate how you can customize the error message by re throwing a new error where we write our own message mixed with the message we get from the original error thrown function dividebigints b1 b2 try return b1 b2 catch error if error instanceof rangeerror throw new error a rangeerror occurred message error message else alert something went wrong try dividebigints bigint 10000000000042 bigint 0 catch error alert error message if you run this example you will now see that because our code generates a rangeerror this error is re thrown and then handled in the last catch block outside of the function here we display the error we received from the function with our own custom error message throwing custom errors as you saw in the previous example throwing an error with a custom message is quite easy we can simply just instantiate a new error object and pass along our own custom message but sometimes this is not enough and just like javascript has specialized error types for various problems like we saw with the rangeerror type we can of course create our own type as well to show you how this works i m going to create a new type of range error which will accept a minimum and a maximum value to give a more informative error message we can do this by creating a class that extends the error class like this class informativerangeerror extends error constructor value min max super value value is not within the valid range must be between min and max this name informativerangeerror notice how our informativerangeerror class accepts three parameters the actual value e g as entered by the user as well as a minimum and a maximum value we then use these three values to generate a much more informative error message which we pass to the original constructor of the error class using the super keyword here s a complete example where we use the class throwing our new informativerangeerror like it was just a regular error class informativerangeerror extends error constructor value min max super value value is not within the valid range must be between min and max this name informativerangeerror let min 1 let max 10 let number number prompt please enter a number if number min number max alert thank you else throw new informativerangeerror number min max if you run this example try entering a value outside of our desired range 1 10 e g 14 if you look in your console you will see our custom error message uncaught informativerangeerror value 14 is not within the valid range must be between 1 and 10 summary javascript comes with different types of errors for different types of problems and if they re not enough you can easily build your own error type we can use these different types both built in and custom to differentiate between what we do for various types of problems by using conditional catching and optionally re throwing the errors we don t want to handle in the place where they occur catching throwing errors try catch finally previous introduction next this article has been fully translated into the following languages czech is your preferred language not on the list click here to help us translate this article into your language javascript tutorial com 2007 2026 contact us suggest correction localization
Thumbnail images (randomly selected): * Images may be subject to copyright.GREEN status (no comments)

    No Images


    Verified site has: 72 subpage(s). Do you want to verify them? Verify pages:

    1-5 6-10 11-15 16-20 21-25 26-30 31-35 36-40 41-45 46-50
    51-55 56-60 61-65 66-70 71-72


    Top 50 hastags from of all verified websites.

    Supplementary Information (add-on for SEO geeks)*- See more on header.verify-www.com

    Header

    HTTP/1.1 302 Redirect
    Content-Type text/html; charset=UTF-8
    Location htt????/javascript-tutorial.com/error-handling/error-types-conditional-catching
    Server Microsoft-IIS/10.0
    X-Powered-By ASP.NET
    Date Thu, 19 Nov 2026 06:39:38 GMT
    Connection close
    Content-Length 202
    HTTP/2 301
    cache-control private
    content-type text/html; charset=utf-8
    location /error-handling/error-types-conditional-catching/
    server Microsoft-IIS/10.0
    set-cookie ASP.NET_SessionId=gtaomvx4mnruiuygoehokkh1; path=/; HttpOnly; SameSite=Lax
    x-aspnetmvc-version 5.2
    x-aspnet-version 4.0.30319
    x-powered-by ASP.NET
    date Thu, 19 Nov 2026 06:39:38 GMT
    content-length 166
    HTTP/2 200
    cache-control private
    content-type text/html; charset=utf-8
    server Microsoft-IIS/10.0
    set-cookie ASP.NET_SessionId=2gn4o5u3tufmdyrkxpem4hhm; path=/; HttpOnly; SameSite=Lax
    x-aspnetmvc-version 5.2
    x-aspnet-version 4.0.30319
    x-powered-by ASP.NET
    date Thu, 19 Nov 2026 06:39:38 GMT
    content-length 27977

    Meta Tags

    title="Error types & conditional catching - The complete JavaScript Tutorial"
    name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"

    Load Info

    page size27977
    load time (s)0.16337
    redirect count2
    speed download171638
    server IP 142.132.248.53
    * all occurrences of the string "http://" have been changed to "htt???/"