- Blog Categories
- Software Development Projects and Ideas
- 12 Computer Science Project Ideas
- 28 Beginner Software Projects
- Top 10 Engineering Project Ideas
- Top 10 Easy Final Year Projects
- Top 10 Mini Projects for Engineers
- 25 Best Django Project Ideas
- Top 20 MERN Stack Project Ideas
- Top 12 Real Time Projects
- Top 6 Major CSE Projects
- 12 Robotics Projects for All Levels
- Java Programming Concepts
- Abstract Class in Java and Methods
- Constructor Overloading in Java
- StringBuffer vs StringBuilder
- Java Identifiers: Syntax & Examples
- Types of Variables in Java Explained
- Composition in Java: Examples
- Append in Java: Implementation
- Loose Coupling vs Tight Coupling
- Integrity Constraints in DBMS
- Different Types of Operators Explained
- Career and Interview Preparation in IT
- Top 14 IT Courses for Jobs
- Top 20 Highest Paying Languages
- 23 Top CS Interview Q&A
- Best IT Jobs without Coding
- Software Engineer Salary in India
- 44 Agile Methodology Interview Q&A
- 10 Software Engineering Challenges
- Top 15 Tech's Daily Life Impact
- 10 Best Backends for React
- Cloud Computing Reference Models
- Web Development and Security
- Find Installed NPM Version
- Install Specific NPM Package Version
- Make API Calls in Angular
- Install Bootstrap in Angular
- Use Axios in React: Guide
- StrictMode in React: Usage
- 75 Cyber Security Research Topics
- Top 7 Languages for Ethical Hacking
- Top 20 Docker Commands
- Advantages of OOP
- Data Science Projects and Applications
- 42 Python Project Ideas for Beginners
- 13 Data Science Project Ideas
- 13 Data Structure Project Ideas
- 12 Real-World Python Applications
- Python Banking Project
- Data Science Course Eligibility
- Association Rule Mining Overview
- Cluster Analysis in Data Mining
- Classification in Data Mining
- KDD Process in Data Mining
- Data Structures and Algorithms
- Binary Tree Types Explained
- Binary Search Algorithm
- Sorting in Data Structure
- Binary Tree in Data Structure
- Binary Tree vs Binary Search Tree
- Recursion in Data Structure
- Data Structure Search Methods: Explained
- Binary Tree Interview Q&A
- Linear vs Binary Search
- Priority Queue Overview
- Python Programming and Tools
- Top 30 Python Pattern Programs
- List vs Tuple
- Python Free Online Course
- Method Overriding in Python
- Top 21 Python Developer Skills
- Reverse a Number in Python
- Switch Case Functions in Python
- Info Retrieval System Overview
- Reverse a Number in Python
- Real-World Python Applications
- Data Science Careers and Comparisons
- Data Analyst Salary in India
- Data Scientist Salary in India
- Free Excel Certification Course
- Actuary Salary in India
- Data Analyst Interview Guide
- Pandas Interview Guide
- Tableau Filters Explained
- Data Mining Techniques Overview
- Data Analytics Lifecycle Phases
- Data Science Vs Analytics Comparison
- Artificial Intelligence and Machine Learning Projects
- Exciting IoT Project Ideas
- 16 Exciting AI Project Ideas
- 45+ Interesting ML Project Ideas
- Exciting Deep Learning Projects
- 12 Intriguing Linear Regression Projects
- 13 Neural Network Projects
- 5 Exciting Image Processing Projects
- Top 8 Thrilling AWS Projects
- 12 Engaging AI Projects in Python
- NLP Projects for Beginners
- Concepts and Algorithms in AIML
- Basic CNN Architecture Explained
- 6 Types of Regression Models
- Data Preprocessing Steps
- Bagging vs Boosting in ML
- Multinomial Naive Bayes Overview
- Gini Index for Decision Trees
- Bayesian Network Example
- Bayes Theorem Guide
- Top 10 Dimensionality Reduction Techniques
- Neural Network Step-by-Step Guide
- Technical Guides and Comparisons
- Make a Chatbot in Python
- Compute Square Roots in Python
- Permutation vs Combination
- Image Segmentation Techniques
- Generative AI vs Traditional AI
- AI vs Human Intelligence
- Random Forest vs Decision Tree
- Neural Network Overview
- Perceptron Learning Algorithm
- Selection Sort Algorithm
- Career and Practical Applications in AIML
- AI Salary in India Overview
- Biological Neural Network Basics
- Top 10 AI Challenges
- Production System in AI
- Top 8 Raspberry Pi Alternatives
- Top 8 Open Source Projects
- 14 Raspberry Pi Project Ideas
- 15 MATLAB Project Ideas
- Top 10 Python NLP Libraries
- Naive Bayes Explained
- Digital Marketing Projects and Strategies
- 10 Best Digital Marketing Projects
- 17 Fun Social Media Projects
- Top 6 SEO Project Ideas
- Digital Marketing Case Studies
- Coca-Cola Marketing Strategy
- Nestle Marketing Strategy Analysis
- Zomato Marketing Strategy
- Monetize Instagram Guide
- Become a Successful Instagram Influencer
- 8 Best Lead Generation Techniques
- Digital Marketing Careers and Salaries
- Digital Marketing Salary in India
- Top 10 Highest Paying Marketing Jobs
- Highest Paying Digital Marketing Jobs
- SEO Salary in India
- Brand Manager Salary in India
- Content Writer Salary Guide
- Digital Marketing Executive Roles
- Career in Digital Marketing Guide
- Future of Digital Marketing
- MBA in Digital Marketing Overview
- Digital Marketing Techniques and Channels
- 9 Types of Digital Marketing Channels
- Top 10 Benefits of Marketing Branding
- 100 Best YouTube Channel Ideas
- YouTube Earnings in India
- 7 Reasons to Study Digital Marketing
- Top 10 Digital Marketing Objectives
- 10 Best Digital Marketing Blogs
- Top 5 Industries Using Digital Marketing
- Growth of Digital Marketing in India
- Top Career Options in Marketing
- Interview Preparation and Skills
- 73 Google Analytics Interview Q&A
- 56 Social Media Marketing Q&A
- 78 Google AdWords Interview Q&A
- Top 133 SEO Interview Q&A
- 27+ Digital Marketing Q&A
- Digital Marketing Free Course
- Top 9 Skills for PPC Analysts
- Movies with Successful Social Media Campaigns
- Marketing Communication Steps
- Top 10 Reasons to Be an Affiliate Marketer
- Career Options and Paths
- Top 25 Highest Paying Jobs India
- Top 25 Highest Paying Jobs World
- Top 10 Highest Paid Commerce Job
- Career Options After 12th Arts
- Top 7 Commerce Courses Without Maths
- Top 7 Career Options After PCB
- Best Career Options for Commerce
- Career Options After 12th CS
- Top 10 Career Options After 10th
- 8 Best Career Options After BA
- Projects and Academic Pursuits
- 17 Exciting Final Year Projects
- Top 12 Commerce Project Topics
- Top 13 BCA Project Ideas
- Career Options After 12th Science
- Top 15 CS Jobs in India
- 12 Best Career Options After M.Com
- 9 Best Career Options After B.Sc
- 7 Best Career Options After BCA
- 22 Best Career Options After MCA
- 16 Top Career Options After CE
- Courses and Certifications
- 10 Best Job-Oriented Courses
- Best Online Computer Courses
- Top 15 Trending Online Courses
- Top 19 High Salary Certificate Courses
- 21 Best Programming Courses for Jobs
- What is SGPA? Convert to CGPA
- GPA to Percentage Calculator
- Highest Salary Engineering Stream
- 15 Top Career Options After Engineering
- 6 Top Career Options After BBA
- Job Market and Interview Preparation
- Why Should You Be Hired: 5 Answers
- Top 10 Future Career Options
- Top 15 Highest Paid IT Jobs India
- 5 Common Guesstimate Interview Q&A
- Average CEO Salary: Top Paid CEOs
- Career Options in Political Science
- Top 15 Highest Paying Non-IT Jobs
- Cover Letter Examples for Jobs
- Top 5 Highest Paying Freelance Jobs
- Top 10 Highest Paying Companies India
- Career Options and Paths After MBA
- 20 Best Careers After B.Com
- Career Options After MBA Marketing
- Top 14 Careers After MBA In HR
- Top 10 Highest Paying HR Jobs India
- How to Become an Investment Banker
- Career Options After MBA - High Paying
- Scope of MBA in Operations Management
- Best MBA for Working Professionals India
- MBA After BA - Is It Right For You?
- Best Online MBA Courses India
- MBA Project Ideas and Topics
- 11 Exciting MBA HR Project Ideas
- Top 15 MBA Project Ideas
- 18 Exciting MBA Marketing Projects
- MBA Project Ideas: Consumer Behavior
- What is Brand Management?
- What is Holistic Marketing?
- What is Green Marketing?
- Intro to Organizational Behavior Model
- Tech Skills Every MBA Should Learn
- Most Demanding Short Term Courses MBA
- MBA Salary, Resume, and Skills
- MBA Salary in India
- HR Salary in India
- Investment Banker Salary India
- MBA Resume Samples
- Sample SOP for MBA
- Sample SOP for Internship
- 7 Ways MBA Helps Your Career
- Must-have Skills in Sales Career
- 8 Skills MBA Helps You Improve
- Top 20+ SAP FICO Interview Q&A
- MBA Specializations and Comparative Guides
- Why MBA After B.Tech? 5 Reasons
- How to Answer 'Why MBA After Engineering?'
- Why MBA in Finance
- MBA After BSc: 10 Reasons
- Which MBA Specialization to choose?
- Top 10 MBA Specializations
- MBA vs Masters: Which to Choose?
- Benefits of MBA After CA
- 5 Steps to Management Consultant
- 37 Must-Read HR Interview Q&A
- Fundamentals and Theories of Management
- What is Management? Objectives & Functions
- Nature and Scope of Management
- Decision Making in Management
- Management Process: Definition & Functions
- Importance of Management
- What are Motivation Theories?
- Tools of Financial Statement Analysis
- Negotiation Skills: Definition & Benefits
- Career Development in HRM
- Top 20 Must-Have HRM Policies
- Project and Supply Chain Management
- Top 20 Project Management Case Studies
- 10 Innovative Supply Chain Projects
- Latest Management Project Topics
- 10 Project Management Project Ideas
- 6 Types of Supply Chain Models
- Top 10 Advantages of SCM
- Top 10 Supply Chain Books
- What is Project Description?
- Top 10 Project Management Companies
- Best Project Management Courses Online
- Salaries and Career Paths in Management
- Project Manager Salary in India
- Average Product Manager Salary India
- Supply Chain Management Salary India
- Salary After BBA in India
- PGDM Salary in India
- Top 7 Career Options in Management
- CSPO Certification Cost
- Why Choose Product Management?
- Product Management in Pharma
- Product Design in Operations Management
- Industry-Specific Management and Case Studies
- Amazon Business Case Study
- Service Delivery Manager Job
- Product Management Examples
- Product Management in Automobiles
- Product Management in Banking
- Sample SOP for Business Management
- Video Game Design Components
- Top 5 Business Courses India
- Free Management Online Course
- SCM Interview Q&A
- Fundamentals and Types of Law
- Acceptance in Contract Law
- Offer in Contract Law
- 9 Types of Evidence
- Types of Law in India
- Introduction to Contract Law
- Negotiable Instrument Act
- Corporate Tax Basics
- Intellectual Property Law
- Workmen Compensation Explained
- Lawyer vs Advocate Difference
- Law Education and Courses
- LLM Subjects & Syllabus
- Corporate Law Subjects
- LLM Course Duration
- Top 10 Online LLM Courses
- Online LLM Degree
- Step-by-Step Guide to Studying Law
- Top 5 Law Books to Read
- Why Legal Studies?
- Pursuing a Career in Law
- How to Become Lawyer in India
- Career Options and Salaries in Law
- Career Options in Law India
- Corporate Lawyer Salary India
- How To Become a Corporate Lawyer
- Career in Law: Starting, Salary
- Career Opportunities: Corporate Law
- Business Lawyer: Role & Salary Info
- Average Lawyer Salary India
- Top Career Options for Lawyers
- Types of Lawyers in India
- Steps to Become SC Lawyer in India
- Tutorials
- C Tutorials
- Recursion in C: Fibonacci Series
- Checking String Palindromes in C
- Prime Number Program in C
- Implementing Square Root in C
- Matrix Multiplication in C
- Understanding Double Data Type
- Factorial of a Number in C
- Structure of a C Program
- Building a Calculator Program in C
- Compiling C Programs on Linux
- Java Tutorials
- Handling String Input in Java
- Determining Even and Odd Numbers
- Prime Number Checker
- Sorting a String
- User-Defined Exceptions
- Understanding the Thread Life Cycle
- Swapping Two Numbers
- Using Final Classes
- Area of a Triangle
- Skills
- Software Engineering
- JavaScript
- Data Structure
- React.js
- Core Java
- Node.js
- Blockchain
- SQL
- Full stack development
- Devops
- NFT
- BigData
- Cyber Security
- Cloud Computing
- Database Design with MySQL
- Cryptocurrency
- Python
- Digital Marketings
- Advertising
- Influencer Marketing
- Search Engine Optimization
- Performance Marketing
- Search Engine Marketing
- Email Marketing
- Content Marketing
- Social Media Marketing
- Display Advertising
- Marketing Analytics
- Web Analytics
- Affiliate Marketing
- MBA
- MBA in Finance
- MBA in HR
- MBA in Marketing
- MBA in Business Analytics
- MBA in Operations Management
- MBA in International Business
- MBA in Information Technology
- MBA in Healthcare Management
- MBA In General Management
- MBA in Agriculture
- MBA in Supply Chain Management
- MBA in Entrepreneurship
- MBA in Project Management
- Management Program
- Consumer Behaviour
- Supply Chain Management
- Financial Analytics
- Introduction to Fintech
- Introduction to HR Analytics
- Fundamentals of Communication
- Art of Effective Communication
- Introduction to Research Methodology
- Mastering Sales Technique
- Business Communication
- Fundamentals of Journalism
- Economics Masterclass
- Free Courses
Exception Handling in Java [With Examples]
Updated on 15 November, 2022
7.19K+ views
• 10 min read
Table of Contents
Exceptions are the unwanted and unexpected event of a program that is never desired by a programmer but has to deal with it so many times. The bright side is that it is possible with the object-oriented language Java to mitigate those undesirable events through a concept called ‘Exception Handling in Java’. It does not repair the exception but provides an alternate way to deal with it.
There can be many reasons for an exception to occur including entry of incorrect data, hardware failure, connection failure, server down, etc. Thus, exception handling is and always will be important in the course of learning Java as it helps to assure the normal flow of a program at the time an unexpected event occurs. Ignoring exceptions may cause the entire software to crash and may result in loss of data.
Now that we got an idea about exceptions and exception handling, let’s dive into it in detail and also understand how Java helps in handling exceptions.
Check out our free courses to get an edge over the competition.
Read: Exception Handling Interview Questions
What is Exception Handling?
A developer can predict the exceptions that a piece of code can throw during runtime. One of the most important things that many of the learners get ambiguous about is that all the exceptions occur during runtime and not at the time of compilation. Java can handle exceptions during runtime only. There are certain keywords used in a java program for creating an exception handler block.
java.lang.Exception is the parent class of all the exception classes. The Exception class is a subclass of the built-in Throwable class which is a subclass of the Object class. Apart from Exception, Throwable also has another class i.e Error which is an abnormal condition during the program execution which cannot be handled by Java programs which are the main difference between Error and Exceptions.
As shown in the above figure, there are mainly two categories of Exceptions in Java. In the next section, we will have a detailed look at the types of exceptions in Java.
Java Exceptions
The root causes of exceptions are the ones caused by the programmer or by physical resources that have failed due to some reasons. Based on these, there are mainly two categories of Exceptions in Java as below details of which are followed:
- Checked exception
- Unchecked exception
1. Checked Exception
Checked exceptions are known as the ‘compile-time exceptions’ as they are checked during compilation by the compiler to monitor if the exception is handled by the programmer. The system then displays a compilation error.
Some examples of these exceptions are IOException, SQLException, NoSuchMethodException, or ClassNotFoundException.
Explore our Popular Software Engineering Courses
Read: Java Project Ideas for Beginners
2. Unchecked Exception
Unchecked exceptions are called ‘Runtime exceptions’ as they occur during the runtime of the program. Unchecked exceptions are normally ignored during the compilation and are not checked.
Examples of these exceptions can be bugs in a program such as logical errors, or using incorrect APIs which are not in the control of a programmer and require a system administrator to rectify.
Check out upGrad’s Java Bootcamp
Checked Vs Unchecked Exception
Differentiating Points | Checked Exception or Compile-Time Exception | Unchecked Exception or Run-Time Exception |
Handling time | Checked Exceptions are checked and handled at the time of compilation. | Unchecked Exceptions are not checked at the time of compilation. |
Exception Identification | The program gives a compilation error if a method throws a checked exception. | The program compiles fine as the compiler cannot check the exception. |
Inheritance | They do not inherit the RuntimeException class. | They are the subclasses of RuntimeException class. |
Developer’s Role | Can be handled by the developers. | Cannot be handled by the developers. |
Check out upGrad’s Advanced Certification in Blockchain
Understanding the exceptions is the primary step before handling them.
Explore Our Software Development Free Courses
How does Java help in Handling Exceptions?
Now that we know there are two types of exceptions in Java viz., checked and unchecked. If a method is throwing a checked exception, it should be handled with a try-catch block or the ‘throws’ keyword should be declared to avoid compilation error in a program.
Example of a Checked Exception:
This is a program of reading a file named ‘Java’. There are three places where a checked exception is thrown:
- FileInputStream: Used for specifying the file path and name throw FileNotFoundException.
- The read() method: Reading the file content throws IOException;
iii. The close() method: Closing the file input stream throws IOException.
import java.io.*;
class Example {
public static void main(String args[])
{
FileInputStream fis = null;
/*The constructor FileInputStream(File filename)
* throws a checked exception FileNotFoundException */
fis = new FileInputStream(“B:/java.txt”);
int k;
/* Method read() of FileInputStream class throws
* a checked exception: IOException
*/
while(( k = fis.read() ) != –1)
{
System.out.print((char)k);
}
/*The method close() closes the file input stream
* throws IOException*/
fis.close();
}
}
In-Demand Software Development Skills
Output Of The Above Program:
Exception found in thread “main” java.lang.Error: Unresolved compilation problems:
Unhandled exception FileNotFoundException found
Unhandled exception IOException found
Unhandled exception IOException found
The reason for this compilation error: Non-declaration or handling of the exceptions.
Popular Articles related to Software Development
upGrad’s Exclusive Software Development Webinar for you –
SAAS Business – What is So Different?
Must Read: Java GitHub Projects
Methods of Exception Handling
There are two ways by which the exceptions can be handled described as below:
Method 1: Declaring the ‘throws’ exception keyword
In the above program, all three checked exceptions are inside the main() method. Thus, one way to avoid the compilation error is to declare the exception in the method using the ‘throws’ keyword. As IOException is a parent class of FileNotFoundException, it will cover that too.
Updated Program using throws keyword:
import java.io.*;
class Example {
public static void main(String args[]) throws IOException
{
FileInputStream fis = null;
fis = new FileInputStream(“B:/java.txt”);
int k;
while(( k = fis.read() ) != –1)
{
System.out.print((char)k);
}
fis.close();
}
}
Output:
Display the content of the file on the screen.
Method 2: Handle exceptions using try-catch blocks.
This is a more advanced approach to the above one and one of the best exception handling practices. The changed program code including the try-catch blocks is as follows:
import java.io.*;
class Example {
public static void main(String args[])
{
FileInputStream fis = null;
try{
fis = new FileInputStream(“B:/java.txt”);
}catch(FileNotFoundException fnfe){
System.out.println(“The file is not “ +
“present at the path specified”);
}
int k;
try{
while(( k = fis.read() ) != –1)
{
System.out.print((char)k);
}
fis.close();
}catch(IOException ioe){
System.out.println(“I/O error “+ioe);
}
}
}
Output:
This code will eventually display the file content.
Example of an Unchecked Exception
The Unchecked exceptions are not checked at the time of compilation. The program won’t give a compilation error if it is not declared or handled and will run fine. The developer’s job is to predict the conditions that may occur in advance causing such exceptions and handle them. All Unchecked exceptions are subclasses of RuntimeException class.
class Example {
public static void main(String args[])
{
int num1=10;
int num2=0;
/*Dividing any number with 0
* Will throw ArithmeticException
*/
int res=num1/num2;
System.out.println(res);
}
}
The code will compile successfully with this code but during runtime, it would throw ArithmeticException as the unchecked exceptions are not checked at compile-time. Let’s take a look at another example.
class Example {
public static void main(String args[])
{
int arr[] ={1,2,3,4,5};
/* The array has 5 elements but we want to
* display the 8th element value. It will throw
* ArrayIndexOutOfBoundsException
*/
System.out.println(arr[7]);
}
}
This code will also compile successfully as ArrayIndexOutOfBoundsException is an unchecked exception.
Here, for handling Unchecked Exceptions, there should be an exception message displayed to the user which he wants to display, but it doesn’t exist in the array.
Handling the above code exception with try-catch block
class Example {
public static void main(String args[]) {
try{
int arr[] ={1,2,3,4,5};
System.out.println(arr[7]);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(“The specified index does not exist “ +
“in the array.”);
}
}
}
Output:
The specified index does not exist in the array.
Note: There can be multiple catch blocks inside a try block for handling different exceptions.
Method 3: Using ‘finally’ keyword
Sometimes it happens that a code needs to be executed even if an exception occurs. This is where the final keyword is used. Here is a typical code with the ‘finally’ keyword.
public int getPlayerScore(String playerFile)
throws FileNotFoundException {
Scanner contents = null;
try {
contents = new Scanner(new File(playerFile));
return Integer.parseInt(contents.nextLine());
} finally {
if (contents != null) {
contents.close();
}
}
}
Here, the final block indicates the code we want Java to run when trying to read the file.
Even if a FileNotFoundException is thrown, Java will call the contents of finally.
We can handle the exception by modifying the code as below:
public int PlayerScore(String playerRuns) {
Scanner contents;
try {
contents = new Scanner(new File(playerRuns));
return Integer.parseInt(contents.nextLine());
} catch (FileNotFoundException noFile ) {
logger.warn(“File not found.”);
return 0;
} finally {
try {
if (contents != null) {
contents.close();
}
} catch (IOException ioexc) {
logger.error(“The reader could not be closed.”, ioexc);
}
}
}
Conclusion
With this article, we have tried to take through the basics of errors and exceptions and exception handling in Java. We hope this guide will give you a good idea of this unique feature that Java offers and you can now handle the exceptions and recover from them better.Conclusion
Java provides ways to handle exceptions right from specific to generic ones. Exceptions that cannot be predicted easily in advance are called unhandled exceptions. Capturing all the exceptions offers visibility to the development team on the quality of the code and the root causes of the errors which can be fixed quickly.
If you’re interested to learn more about Java, full stack development, check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development. It is carefully curated for professionals and assures 360 degree career support and includes live projects to work on. By the end of the course, you will be able to design and build applications like Swiggy, IMDB, etc.
Doesn’t that sound exciting!-
Frequently Asked Questions (FAQs)
1. What exactly is an exception in a programming language?
In programming, an exception can be any kind of unplanned or unforeseen event that occurs during runtime and disrupts the natural course of the program execution. An invalid or unacceptable input or a sudden drop in network connectivity are the most common examples of an exception. Programmers develop code modules to handle exceptions, such that the flow of the program remains uninterrupted. But there might be unchecked exceptions – those which occur during the compilation phase of the program and cannot be handled. Such exceptions are fatal since they prompt the operating system to force close the program. Errors are typical examples of unchecked exceptions.
2. Should exceptions be used at all times?
Exception handling offers a graceful method of dealing with a sudden problem in the flow of a program. There are some standard cases when it is essential or rather mandatory to use exceptions. For instance, use exception handling only in exceptional conditions, like, when something cannot be recovered. A program riddled with many exceptions is undesirable and becomes too expensive to maintain. Exceptions should ideally be used to deal with external problems, like connectivity issues with the database. But, there are also times when you should not use an exception. For example, exceptions should never be used to control the flow of program logic.
3. Does C programming language support exception handling?
The C programming language does not offer direct means of exception handling or even error handling. But it is possible to write code for error and exception handling in C. To make this possible in C, a programmer must ensure error-free coding and validate values returned by the functions they code. Many C functions return NULL or -1 in case of errors. So writing code to test the values is the best way to detect and handle errors. Different error handling methods in C include functions like perror() and strerror(), EXIT_SUCCESS, EXIT_FAILURE, errno global variable, and divide by zero error.
RELATED PROGRAMS