- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to define custom JavaScript exceptions?
To learn how to define and implement custom JavaScript exceptions, you can try to run the following code −
Example
<html> <head> <script> <!-- function myFunc() { var a = 30; var b = 0; try{ if ( b == 0 ){ throw( "Divide by zero error." ); } else { var c = a / b; } } catch ( e ) { alert("Error: " + e ); } } //--> </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
- Related Articles
- How to use Custom Exceptions in JavaScript?
- How to define custom sort function in JavaScript?
- How to declare custom exceptions in modern Python?
- Custom exceptions in Java
- What are custom exceptions in Java?
- How to define custom methods in C#?
- How to catch exceptions in JavaScript?
- How to write custom Python Exceptions with Error Codes and Error Messages?
- User defined and custom exceptions in Java
- What are the custom exceptions in C#?
- How can I add condition in custom exceptions in java?
- How to catch all JavaScript unhandled exceptions?
- How does Exceptions Handling work in JavaScript?
- How to create a custom object in JavaScript?
- How to define a method in JavaScript?

Advertisements