 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can we write code in try/catch block in JSP as well?
If you want to handle errors within the same page and want to take some action instead of firing an error page, you can make use of the try....catch block.
Following is a simple example which shows how to use the try...catch block. Let us put the following code in main.jsp −
<html>    <head>       <title>Try...Catch Example</title>    </head>    <body>       <%          try {             int i = 1;             i = i / 0;             out.println("The answer is " + i);          }          catch (Exception e) {           out.println("An exception occurred: " + e.getMessage());          }       %>    </body> </html> Access the main.jsp, it should generate an output somewhat like the following −
An exception occurred: / by zero
Advertisements
 