Java basic learning content 7 (exception)

How to define your own exception class

Unique exception


  public class MyException extends Exception {
    ...
  }

try If an exception occurs in the try block, the processing is interrupted and the catch block is processed.

try


  ...
  void method(){
    try{
      ...
    } catch (MyException1 | MyException2 e){
      ...
    } catch (MyException3 e){
      ...
    } finaly {
      ...
    }   
  }

# throws, throw
Use throws when a method may pass an exception to the caller.
Also, use throw when explicitly throwing an exception. l


#### **`throws`**
```java

class classA {
  void methodA() throes MyExceptionA {
    ...
    if(isError){
      throw new MyException();
    }
    ...
  }

}

Recommended Posts

Java basic learning content 7 (exception)
Java basic learning content 5 (modifier)
Java Basic Learning Content 8 (Java API)
Java basic learning content 4 (repetition)
Java basic learning content 3 (operator / ternary operator)
Java basic learning content 9 (lambda expression)
Java basic learning content 2 (array / ArrayList)
Java learning memo (basic)
Java basic learning content 1 (literals, variables, constants)
Java Basic Learning Content 6 (Inheritance / Abstract Class / Interface)
Java learning (0)
[Java] Exception types and basic processing
Java exception handling?
For JAVA learning (2018-03-16-01)
Java learning day 5
Java basic grammar
Java basic grammar
[Java] Exception instance
Java basic knowledge 1
[Java] Basic structure
[Java] [Basic] Glossary
Java basic grammar
Java basic grammar
[Java] Exception handling
☾ Java / Exception handling
Java exception handling
Java exception handling
Java exercises [Basic]
java learning day 2
java learning day 1
Ruby learning points (basic)
Java learning 2 (learning calculation method)
java learning (conditional expression)
[java] throw an exception
java basic knowledge memo
Java learning memo (method)
Java Learning (1)-Hello World
[Java] Data type ①-Basic type
Java basic date manipulation
JAVA learning history interface
Java basic naming conventions
Java learning memo (interface)
Java learning memo (inheritance)
[Java] Basic method notes
Java basic data types
Basic Java OOps concepts
Learning Java framework # 1 (Mac version)
Basic Authentication with Java 11 HttpClient
Java basic syntax + α trap
JAVA learning history interface inheritance
Java learning memo (data type)
[Java] Practice of exception handling [Exception]
[Java] Basic statement for beginners
Books used for learning Java
4th day of java learning
[Java] About try-catch exception handling
Ruby on Rails basic learning ①
[Java] Thymeleaf Basic (Spring Boot)
Java exception handling usage rules
Implement Basic authentication in Java
Java learning memo (logical operator)