“Java -Ausnahme” Code-Antworten

Werfen Sie IO -Ausnahme Java

public static void foo() throws IOException {
    // some code here, when something goes wrong, you might do:
    throw new IOException("error message");
}

public static void main(String[] args) {
    try {
        foo();
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
}
Angry Albatross (Old)

Versuchen Sie, Java zu fangen

public class MyClass {
  public static void main(String[ ] args) {
    try {
      int[] myNumbers = {1, 2, 3, 4, 5, 6};
      System.out.println(myNumbers[10]);
    } catch (Exception e) {
      System.out.println("Something went wrong. check again");
    }
  }
}
 
Mr. Samy

Java -Ausnahme

    - ArithmeticException 
    It is thrown when an exceptional condition has occurred in an arithmetic operation.
    
    - ArrayIndexOutOfBoundsException 
    It is thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.
    
    - ClassNotFoundException 
    This Exception is raised when we try to access a class whose definition is not found
    
    - FileNotFoundException 
    This Exception is raised when a file is not accessible or does not open.
    
    - IOException 
    It is thrown when an input-output operation failed or interrupted
    
    - InterruptedException 
    It is thrown when a thread is waiting, sleeping, or doing some processing, and it is interrupted.
    
    - NoSuchFieldException 
    It is thrown when a class does not contain the field (or variable) specified
    
    - NoSuchMethodException 
    It is thrown when accessing a method which is not found.
    
    - NullPointerException 
    This exception is raised when referring to the members of a null object. Null represents nothing
    
    - NumberFormatException 
    This exception is raised when a method could not convert a string into a numeric format.
    
    - RuntimeException 
    This represents any exception which occurs during runtime.
    
    - StringIndexOutOfBoundsException 
    It is thrown by String class methods to indicate that an index is either negative or greater than the size of the string
Strange Starling

Ausnahmebehandlung in Java

public class JavaExceptionExample{  
  public static void main(String args[]){  
   try{  
      //code that may raise exception  
      int data=100/0;  
   }catch(ArithmeticException e){System.out.println(e);}  
   //rest code of the program   
   System.out.println("rest of the code...");  
  }  
}  
NajmAdin

Implementierung der Ausnahmeklassen in Java

public class JavaExceptionExample extends Exception{  
  public JavaExceptionExample(){
  }
   public JavaExceptionExample(String s){
     //String parameter which is the detail message of the exception.
  }
}  
Lukatic

Was ist eine Ausnahme in Java

Exception is an abnormal condition.
There are mainly two types of exceptions: checked and unchecked.
An error is considered as the unchecked exception. However, according to Oracle, 
there are three types of exceptions namely:
1. Checked Exception
2. Unchecked Exception
3. Error   
Tiny Coders

Ähnliche Antworten wie “Java -Ausnahme”

Fragen ähnlich wie “Java -Ausnahme”

Weitere verwandte Antworten zu “Java -Ausnahme” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen