Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
There are a lot of similar java terms which seems to be confusing.

1 Answer

0 votes
by (11.3k points)

When you have to throw an exception manually, you should use the throw keyword. This gives you the flexibility of throwing an exception as required from any block of code or function. This comes with the constraint that the exception must be of the type, java.lang.Throwable. When you work on big development projects, knowing proper exception handling is quintessential. You can take up a java certification course to get these concepts clear. Here's how 'throw' is implemented:

1

2

3

4

5

6

7

8

9

class Example

{

    void method() throws Exception

    {

        Exception e = new Exception();

        throw e;           

    }

}

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 20, 2020 in Java by angadmishra (6.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...