Exception

Mosquera

Mitglied
Moin,

ich habe gerade versucht eine Exception abzufangen, er führt auch den Anweisungsblock aus, aber komischerweise erscheint die Exception trotzdem in der Konsole.
Ich pack euch hier mal den Code rein.
Java:
package ebkherne.hbit3.gaußalgorithmus;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Logik extends JPanel implements ActionListener {

    private JLabel lblError, lbl_X1, lbl_X2, lbl_X3, lbl_Erg;
    private JTextField txt_1X1, txt_1X2, txt_1X3, txt_1Erg;
    private JTextField txt_2X1, txt_2X2, txt_2X3, txt_2Erg;
    private JTextField txt_3X1, txt_3X2, txt_3X3, txt_3Erg;
    private JButton btnBerechnen;
    private Double[][] Matrix = new Double[3][4];
    private Double[][] Matrix_2 = new Double[3][4];
    private Double[][] Matrix_3 = new Double[3][4];
    private Double[][] Matrix_4 = new Double[3][4];
   
   
    public Logik(int X, int Y) {
       
       
        // erste Reihe
        txt_1X1 = new JTextField();
        txt_1X1.setBounds(20, 40, 100, 20);
        this.add(txt_1X1);
       
        txt_1X2 = new JTextField();
        txt_1X2.setBounds(130, 40, 100, 20);
        this.add(txt_1X2);
       
        txt_1X3 = new JTextField();
        txt_1X3.setBounds(240, 40, 100, 20);
        this.add(txt_1X3);
       
        txt_1Erg = new JTextField();
        txt_1Erg.setBounds(350, 40, 100, 20);
        this.add(txt_1Erg);
       
        // zweite Reihe
        txt_2X1 = new JTextField();
        txt_2X1.setBounds(20, 80, 100, 20);
        this.add(txt_2X1);
           
        txt_2X2 = new JTextField();
        txt_2X2.setBounds(130, 80, 100, 20);
        this.add(txt_2X2);
               
        txt_2X3 = new JTextField();
        txt_2X3.setBounds(240, 80, 100, 20);
        this.add(txt_2X3);
               
        txt_2Erg = new JTextField();
        txt_2Erg.setBounds(350, 80, 100, 20);
        this.add(txt_2Erg);
       
        // dritte Reihe
        txt_3X1 = new JTextField();
        txt_3X1.setBounds(20, 120, 100, 20);
        this.add(txt_3X1);
                   
        txt_3X2 = new JTextField();
        txt_3X2.setBounds(130, 120, 100, 20);
        this.add(txt_3X2);
                       
        txt_3X3 = new JTextField();
        txt_3X3.setBounds(240, 120, 100, 20);
        this.add(txt_3X3);
                       
        txt_3Erg = new JTextField();
        txt_3Erg.setBounds(350, 120, 100, 20);
        this.add(txt_3Erg);
       
        // Button
        btnBerechnen = new JButton("Berechnen");
        btnBerechnen.setBounds(350, 160, 100, 20);
        this.add(btnBerechnen);
        btnBerechnen.addActionListener(this);
       
        // Labels
        lblError = new JLabel();
        lblError.setBounds(20, 160, 300, 20);
        this.add(lblError);
       
        lbl_X1 = new JLabel("X1");
        lbl_X1.setBounds(20, 10, 100, 20);
        this.add(lbl_X1);
       
        lbl_X2 = new JLabel("X2");
        lbl_X2.setBounds(130, 10, 100, 20);
        this.add(lbl_X2);
       
        lbl_X3 = new JLabel("X3");
        lbl_X3.setBounds(240, 10, 100, 20);
        this.add(lbl_X3);
       
        lbl_Erg = new JLabel("Ergebnis");
        lbl_Erg.setBounds(350, 10, 100, 20);
        this.add(lbl_Erg);
       
        this.setPreferredSize(new Dimension(X, Y));
        this.setLayout(null);
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
       
        if(ae.getActionCommand().equals("Berechnen")) {
           
            // Fang Exception ab
            try {
                Matrix[0][0] = Double.parseDouble(txt_1X1.getText());
                Matrix[0][1] = Double.parseDouble(txt_1X2.getText());
                Matrix[0][2] = Double.parseDouble(txt_1X3.getText());
                Matrix[0][3] = Double.parseDouble(txt_1Erg.getText());
               
                Matrix[1][0] = Double.parseDouble(txt_2X1.getText());
                Matrix[1][1] = Double.parseDouble(txt_2X2.getText());
                Matrix[1][2] = Double.parseDouble(txt_2X3.getText());
                Matrix[1][3] = Double.parseDouble(txt_2Erg.getText());
               
                Matrix[2][0] = Double.parseDouble(txt_3X1.getText());
                Matrix[2][1] = Double.parseDouble(txt_3X2.getText());
                Matrix[2][2] = Double.parseDouble(txt_3X3.getText());
                Matrix[2][3] = Double.parseDouble(txt_3Erg.getText());
            } catch (NumberFormatException nfe) {
                lblError.setText("Überprüfen Sie bitte die Felder!");
            }
           
            // Zahlen in Array übergeben
            // Keine Ahnung was hiermit passieren soll
            Matrix[0][0] = Double.parseDouble(txt_1X1.getText());
            Matrix[0][1] = Double.parseDouble(txt_1X2.getText());
            Matrix[0][2] = Double.parseDouble(txt_1X3.getText());
            Matrix[0][3] = Double.parseDouble(txt_1Erg.getText());
           
            Matrix[1][0] = Double.parseDouble(txt_2X1.getText());
            Matrix[1][1] = Double.parseDouble(txt_2X2.getText());
            Matrix[1][2] = Double.parseDouble(txt_2X3.getText());
            Matrix[1][3] = Double.parseDouble(txt_2Erg.getText());
           
            Matrix[2][0] = Double.parseDouble(txt_3X1.getText());
            Matrix[2][1] = Double.parseDouble(txt_3X2.getText());
            Matrix[2][2] = Double.parseDouble(txt_3X3.getText());
            Matrix[2][3] = Double.parseDouble(txt_3Erg.getText());
           
            // I und II angleichen
            double Erg_I_Mal_II_1 = Matrix[0][0] * Matrix[1][0];
            double Erg_I_Mal_II_2 = Matrix[0][0] * Matrix[1][1];
            double Erg_I_Mal_II_3 = Matrix[0][0] * Matrix[1][2];
            double Erg_I_Mal_II_4 = Matrix[0][0] * Matrix[1][3];
           
            double Erg_II_Mal_I_1 = Matrix[1][0] * Matrix[0][0];
            double Erg_II_Mal_I_2 = Matrix[1][0] * Matrix[0][1];
            double Erg_II_Mal_I_3 = Matrix[1][0] * Matrix[0][2];
            double Erg_II_Mal_I_4 = Matrix[1][0] * Matrix[0][3];
           
            // I - II
            double Erg_I_Minus_II_1 = Erg_I_Mal_II_1 - Erg_II_Mal_I_1;
            double Erg_I_Minus_II_2 = Erg_I_Mal_II_2 - Erg_II_Mal_I_2;
            double Erg_I_Minus_II_3 = Erg_I_Mal_II_3 - Erg_II_Mal_I_3;
            double Erg_I_Minus_II_4 = Erg_I_Mal_II_4 - Erg_II_Mal_I_4;
           
            // neue Matrix - neue Werte übernehmen
            Matrix_2[0][0] = Matrix[0][0];
            Matrix_2[0][1] = Matrix[0][1];
            Matrix_2[0][2] = Matrix[0][2];
            Matrix_2[0][3] = Matrix[0][3];
           
            Matrix_2[1][0] = Erg_I_Minus_II_1;
            Matrix_2[1][1] = Erg_I_Minus_II_2;
            Matrix_2[1][2] = Erg_I_Minus_II_3;
            Matrix_2[1][3] = Erg_I_Minus_II_4;
           
            Matrix_2[2][0] = Matrix[2][0];
            Matrix_2[2][1] = Matrix[2][1];
            Matrix_2[2][2] = Matrix[2][2];
            Matrix_2[2][3] = Matrix[2][3];
           
            // I und III angleichen
            double Erg_I_Mal_III_1 = Matrix_2[0][0] * Matrix_2[2][0];
            double Erg_I_Mal_III_2 = Matrix_2[0][0] * Matrix_2[2][1];
            double Erg_I_Mal_III_3 = Matrix_2[0][0] * Matrix_2[2][2];
            double Erg_I_Mal_III_4 = Matrix_2[0][0] * Matrix_2[2][3];
           
            double Erg_III_Mal_I_1 = Matrix_2[2][0] * Matrix_2[0][0];
            double Erg_III_Mal_I_2 = Matrix_2[2][0] * Matrix_2[0][1];
            double Erg_III_Mal_I_3 = Matrix_2[2][0] * Matrix_2[0][2];
            double Erg_III_Mal_I_4 = Matrix_2[2][0] * Matrix_2[0][3];
           
            // I - III
            double Erg_I_Minus_III_1 = Erg_I_Mal_III_1 - Erg_III_Mal_I_1;
            double Erg_I_Minus_III_2 = Erg_I_Mal_III_2 - Erg_III_Mal_I_2;
            double Erg_I_Minus_III_3 = Erg_I_Mal_III_3 - Erg_III_Mal_I_3;
            double Erg_I_Minus_III_4 = Erg_I_Mal_III_4 - Erg_III_Mal_I_4;
           
            // neue Matrix - neue Werte übernehmen
            Matrix_3[0][0] = Matrix_2[0][0];
            Matrix_3[0][1] = Matrix_2[0][1];
            Matrix_3[0][2] = Matrix_2[0][2];
            Matrix_3[0][3] = Matrix_2[0][3];
           
            Matrix_3[1][0] = Matrix_2[1][0];
            Matrix_3[1][1] = Matrix_2[1][1];
            Matrix_3[1][2] = Matrix_2[1][2];
            Matrix_3[1][3] = Matrix_2[1][3];
           
            Matrix_3[2][0] = Erg_I_Minus_III_1;
            Matrix_3[2][1] = Erg_I_Minus_III_2;
            Matrix_3[2][2] = Erg_I_Minus_III_3;
            Matrix_3[2][3] = Erg_I_Minus_III_4;
           
            // II und III angleichen
            double Erg_II_Mal_III_1 = Matrix_3[1][1] * Matrix_3[2][0];
            double Erg_II_Mal_III_2 = Matrix_3[1][1] * Matrix_3[2][1];
            double Erg_II_Mal_III_3 = Matrix_3[1][1] * Matrix_3[2][2];
            double Erg_II_Mal_III_4 = Matrix_3[1][1] * Matrix_3[2][3];
           
            double Erg_III_Mal_II_1 = Matrix_3[2][1] * Matrix_3[1][0];
            double Erg_III_Mal_II_2 = Matrix_3[2][1] * Matrix_3[1][1];
            double Erg_III_Mal_II_3 = Matrix_3[2][1] * Matrix_3[1][2];
            double Erg_III_Mal_II_4 = Matrix_3[2][1] * Matrix_3[1][3];
           
            // II - III   
            double Erg_II_Minus_III_1 = Erg_II_Mal_III_1 - Erg_III_Mal_II_1;
            double Erg_II_Minus_III_2 = Erg_II_Mal_III_2 - Erg_III_Mal_II_2;
            double Erg_II_Minus_III_3 = Erg_II_Mal_III_3 - Erg_III_Mal_II_3;
            double Erg_II_Minus_III_4 = Erg_II_Mal_III_4 - Erg_III_Mal_II_4;
           
            // neue Matrix - neue Werte übernehmen
            Matrix_4[0][0] = Matrix_3[0][0];
            Matrix_4[0][1] = Matrix_3[0][1];
            Matrix_4[0][2] = Matrix_3[0][2];
            Matrix_4[0][3] = Matrix_3[0][3];
           
            Matrix_4[1][0] = Matrix_3[1][0];
            Matrix_4[1][1] = Matrix_3[1][1];
            Matrix_4[1][2] = Matrix_3[1][2];
            Matrix_4[1][3] = Matrix_3[1][3];
           
            Matrix_4[2][0] = Erg_II_Minus_III_1;
            Matrix_4[2][1] = Erg_II_Minus_III_2;
            Matrix_4[2][2] = Erg_II_Minus_III_3;
            Matrix_4[2][3] = Erg_II_Minus_III_4;
           
            System.out.println("Letzte Matrix: ");
            for (int row = 0; row < 3; row++) {
                for (int column = 0; column < 4; column++) {
                    System.out.print(Matrix_4[row][column] + "  ");
                }
                System.out.println();
            }
            System.out.println();
           
            // verbleibene Variable in III. Gleichung nach Variable auflösen und Ergebnis zwischenspeichern
            double Erg_Z = Matrix_4[2][3] / Matrix_4[2][2];
           
            // Ergebnis in II einsetzen, nach Variable auflösen und zwischenspeichern
            double Erg_Y_1 = Matrix_4[1][3] - Matrix_4[1][2] * (Erg_Z);
            double Erg_Y_2 = Erg_Y_1 / Matrix_4[1][1];
           
            // beide Variablen in I einsetzen, nach Variable auflösung und Ergebnis zwischenspeichern
            double Erg_X_1 = Matrix_4[0][3] - (Matrix_4[0][1] * Erg_Y_2 + Matrix_4[0][2] * (Erg_Z));
            double Erg_X_2 = Erg_X_1 / Matrix_4[0][0];
           
            // Ergebnis präsentieren
            System.out.println("Z-Ergebnis: " + Erg_Z);
            System.out.println("Y-Ergebnis: " + Erg_Y_2);
            System.out.println("X-Ergebnis: " + Erg_X_2);
        }
   
    }

}

Ich bedanke mich im Voraus!

Mit freundlichen Grüßen,
Leon Dossin
 

mrBrown

Super-Moderator
Mitarbeiter
Du fängst die Exception ab, führst danach (bei "// Keine Ahnung was hiermit passieren soll") aber noch mal das gleiche aus, wodurch die gleiche Exception noch mal geworfen wird.

So wie ich das kenne erscheint in der Konsole immer, dass eine Exception abgefangen wurde.
Nein, da tauchen nur nicht-gefangene Exceptoin oder das, was man selbst ausgeben lässt.
 

Mosquera

Mitglied
Habe die Lösung. Ich musste im catch nach dem setzen des Textes noch ein return dran hängen.
Das ist das doppelt hatte war kein Problem, trotzdem danke für alle Antworten.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
I Exception wird gefangen, aber trotzdem in Error Log? Java Basics - Anfänger-Themen 10
W Null-Pointer Exception beim Programmstart Java Basics - Anfänger-Themen 8
Ostkreuz String Exception Java Basics - Anfänger-Themen 8
Fiedelbambu Exception in Application constructor Java Basics - Anfänger-Themen 3
S leeres Array statt Null Pointer Exception ausgeben Java Basics - Anfänger-Themen 20
F abbruch Exception lässt sich nicht erstellen Java Basics - Anfänger-Themen 2
U Warum kriege ich hier eine nullpointer exception, sehe den Fehler nicht (swing) Java Basics - Anfänger-Themen 1
F Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11 at main.main(main.java:11) Java Basics - Anfänger-Themen 2
M Exception in thread "main" java.util.NoSuchElementException Java Basics - Anfänger-Themen 2
N Exception beim Verwenden von Arraylist? Java Basics - Anfänger-Themen 10
B Compiler-Fehler Fehlermeldung Exception in thread, falsche Eingabewert Java Basics - Anfänger-Themen 2
S JavaKara Null Exception Error Java Basics - Anfänger-Themen 4
T Eigene Exception - ohne werfen abfangen Java Basics - Anfänger-Themen 2
LiFunk Exception: es dürfen nur Nummern eingelesen werden Java Basics - Anfänger-Themen 6
low_in_the_head Eigene Exception nutzen Java Basics - Anfänger-Themen 4
1 Exception Java Basics - Anfänger-Themen 2
S Kriege Fehler "Exception in thread" beim Benutzen von SubStrings. Java Basics - Anfänger-Themen 2
I JAX-RS Exception Handling Java Basics - Anfänger-Themen 4
L Meine erste eigene Exception Klasse Java Basics - Anfänger-Themen 10
J null exception Array Java Basics - Anfänger-Themen 5
H Frage zu Throw Exception Java Basics - Anfänger-Themen 2
O Exception in thread "main" java.lang.ArithmeticException: / by zero Java Basics - Anfänger-Themen 4
M Wie kann ich bei int-Variablen im exception handler auf bestimmte Strings reagieren? Java Basics - Anfänger-Themen 5
C Exception-Frage Java Basics - Anfänger-Themen 3
B Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException Java Basics - Anfänger-Themen 8
I Exception bei Button mit wait() und notifyAll() Java Basics - Anfänger-Themen 3
N Wie teste ich eine geworfene Exception? Java Basics - Anfänger-Themen 8
R Methoden ArrayList clonen wirft exception Java Basics - Anfänger-Themen 3
D Scanner- Exception NoSuchElementException Java Basics - Anfänger-Themen 2
N Exception werfen bei falscher Datumseingabe Java Basics - Anfänger-Themen 14
A Exception handeling mit finally und objektreferenzen Java Basics - Anfänger-Themen 6
D Frage zu Strings einer Exception Java Basics - Anfänger-Themen 4
S Exception Java Basics - Anfänger-Themen 2
J Exception-Aufgabe Java Basics - Anfänger-Themen 8
S Verwenden von throw Exception an der Funktion Java Basics - Anfänger-Themen 2
R Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 5
S Compiler-Fehler Exception in thread "main" java.lang.Error: Unresolved compilation problem: Java Basics - Anfänger-Themen 6
Z Fragen zu Exception (Throws/throw) Java Basics - Anfänger-Themen 7
OSchriever Exception für Abbrechen-Schaltfläche JOptionpane Java Basics - Anfänger-Themen 9
J Dateien in Verzeichnissen rekursiv auflisten wirft Exception Java Basics - Anfänger-Themen 4
J Exception unreachable Java Basics - Anfänger-Themen 12
O unchecked Exception Java Basics - Anfänger-Themen 4
P Exception werfen Java Basics - Anfänger-Themen 15
B EJB und Arquillian - bekomme Nullpointer Exception beim Aufruf der EJB Klasse Java Basics - Anfänger-Themen 40
S Exception bei Verwendung von LocalDate Java Basics - Anfänger-Themen 19
I Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 Java Basics - Anfänger-Themen 3
D Warum die Nullpointer Exception Java Basics - Anfänger-Themen 6
O Exception behandlung einfach Ueben mit Fakt! Java Basics - Anfänger-Themen 10
I OOP Was ist die "Exception Hierarchie" ? Java Basics - Anfänger-Themen 3
U Null Exception aber keine Ahnung warum Java Basics - Anfänger-Themen 5
G Exception und Ausgabe der Duplikate Java Basics - Anfänger-Themen 6
H Try Catch Throw Exception Java Basics - Anfänger-Themen 1
W Exception in Main abfangen oder in der Methode? Java Basics - Anfänger-Themen 10
F Referenz an ein Objekt in einer anderen Klasse erstellen(Nullpointer exception) Java Basics - Anfänger-Themen 6
M rekursive division/0 mit exception Java Basics - Anfänger-Themen 18
N Nullpointer exception Java Basics - Anfänger-Themen 4
L Eigene Exception schreiben bei zu langem Array Java Basics - Anfänger-Themen 10
R Exception in thread "main" java.lang.NullPointerException Java Basics - Anfänger-Themen 10
I equals (Override) mit eigener Exception (keine Runtime-Exception) Java Basics - Anfänger-Themen 9
S Array Grenzen-Exception Java Basics - Anfänger-Themen 11
E InputStream im Servlet wirft Exception Java Basics - Anfänger-Themen 5
D Erste Schritte Java.lang.NullPointer.Exception Java Basics - Anfänger-Themen 8
G Arrays out of Bounds exception Java Basics - Anfänger-Themen 2
H Compiler-Fehler Out of Bunce Exception bei einem Char Java Basics - Anfänger-Themen 6
C Compiler-Fehler Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 Java Basics - Anfänger-Themen 3
C Null Pointer Exception Java Basics - Anfänger-Themen 10
F Klassen Eigene Exception Bedingungen festlegen Java Basics - Anfänger-Themen 2
G Null Pointer Exception Java Basics - Anfänger-Themen 4
GreenTeaYT Exception und zur OOP fragen? Java Basics - Anfänger-Themen 3
O Exception bei Parse-Vorgang Java Basics - Anfänger-Themen 17
T Exception Problem Java Basics - Anfänger-Themen 5
Z Getter/Setter NullPointer Exception Java Basics - Anfänger-Themen 6
W Nullpointer Exception bei .add(...) Java Basics - Anfänger-Themen 6
L Input/Output InputMismatch.Exception Java Basics - Anfänger-Themen 7
B Exception Liste von Liste Java Basics - Anfänger-Themen 3
D Throw Exception Java Basics - Anfänger-Themen 2
MiMa JavaDoc Exception @throws schlagen an Java Basics - Anfänger-Themen 4
J Exception in thread "main" Java Basics - Anfänger-Themen 1
B Exception richtig einbinden Java Basics - Anfänger-Themen 1
M Exception soll Werte mitgeliefert bekommen Java Basics - Anfänger-Themen 12
M Selbstdefinierte Exception Java Basics - Anfänger-Themen 5
B Exception Throwable Java Basics - Anfänger-Themen 11
M Erste Schritte Start Methode - Exception Java Basics - Anfänger-Themen 1
F Operatoren Wieso fliegt hier eine NullPointer Exception :( Java Basics - Anfänger-Themen 3
F nullpointer exception - arrayerstellung Java Basics - Anfänger-Themen 4
K Iterator-Interface implementieren mit Exception Handlung Java Basics - Anfänger-Themen 1
H Erste Schritte Exception: 0 Java Basics - Anfänger-Themen 2
A Exception vs. Testklasse (Programm testen) Java Basics - Anfänger-Themen 2
L Fehler: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException Java Basics - Anfänger-Themen 4
K Exception nur im "Debug"-Modus und jedem 3.-5. mal Ausführen Java Basics - Anfänger-Themen 3
S Java memory fehler: Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa Java Basics - Anfänger-Themen 5
L [JFrame] Exception - woher? Java Basics - Anfänger-Themen 8
N Threads Exception in thread "main"... Feher bei dem Versuch ein Radius zu berechnen Java Basics - Anfänger-Themen 4
R "Missbrauch" von Exception zum Programmfluss Java Basics - Anfänger-Themen 1
U Exception: OutOfMemoryError Java Basics - Anfänger-Themen 11
A Int Eingabe: String mit Exception abfangen. Aber wie? Java Basics - Anfänger-Themen 3
A Code läuft nicht, Fehlermeldung Exception in thread "main" java.lang.Error: Unresolved compilation " Java Basics - Anfänger-Themen 11
V Threads Exception in Thread behandeln Java Basics - Anfänger-Themen 3
F Java exception bei der Ausführung Java Basics - Anfänger-Themen 10
J Exception für String Java Basics - Anfänger-Themen 9

Ähnliche Java Themen

Neue Themen


Oben