Announcement

Collapse
No announcement yet.

Seltsames Verhalten bei Exception

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Seltsames Verhalten bei Exception

    Hallo,
    ich erstelle gerade eine Windowsanwendung die aus ein Hauptformular und ein paar „Unterformularen“ (Usercontrol die ich in ein Panel lade) besteht.
    Die Anwendung liest unter anderem einige Dateien ein. Wenn diese nicht vorhanden sind löse ich eine Exception aus. Wenn ich das ganze im Visual Studio ausführe und teste, funktioniert alles bestens. Wenn ich jedoch direkt die exe ausführe wird die Exception nicht aufgefangen. Stattdessen erscheint eine Meldung der Laufzeitumgebung („Nicht behandelte Exception…“)

    Wie gesagt das Problem tritt nur auf wenn ich die exe direkt ausführe…beim start in Visual Studio wird diese Exception aufgefangen…

    Wie kann das sein?

  • #2
    Woher liest du die Daten ein und wie lautet der Text der Exception - da steht sicher mehr.

    mfG Gü
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

    Comment


    • #3
      Das einlesen wer nur ein Beispiel. Das Problem tritt auch auf wenn ich eine eigene Exception auslöse.

      Hier mal ein Codebeispiel:

      Code:
       try
                  {
                      Application.EnableVisualStyles();
                      Application.SetCompatibleTextRenderingDefault(false);
                      Application.Run(new Form1());
                  }     
                   catch (Exception e )
                  {
                      MessageBox.Show(e.Message);
                      
                  }
      Dann löse ich in Form1 eine Exception aus.

      Code:
      throw new Exception("Hier läuft was schief");
      In Visual Studio wird die Exception korrekt gefangen und das gemacht, was im catch Block steht.

      Bei direkter Ausführung kommt folgendes:

      Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.


      See the end of this message for details on invoking
      just-in-time (JIT) debugging instead of this dialog box.

      ************** Exception Text **************
      System.Exception: Hier läuft was schief
      at WindowsFormsApplication1.Form1.Form1_Load(Object sender, EventArgs e) in C:\WindowsFormsApplication1\WindowsFormsApplicatio n1\Form1.cs:line 21
      at System.Windows.Forms.Form.OnLoad(EventArgs e)
      at System.Windows.Forms.Form.OnCreateControl()
      at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
      at System.Windows.Forms.Control.CreateControl()
      at System.Windows.Forms.Control.WmShowWindow(Message& m)
      at System.Windows.Forms.Control.WndProc(Message& m)
      at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
      at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
      at System.Windows.Forms.Form.WmShowWindow(Message& m)
      at System.Windows.Forms.Form.WndProc(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
      at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

      ...

      Die Exception wird ja geworfen nur nicht Behandelt ?! Seh ich das richtig?

      Comment


      • #4
        Der globale unbehandelte Exceptionhandler hängt in Application.Run (und zieht nur wenn kein Debugger attached ist). Ein Exceptionblock danach läuft also ins Leere.

        Behandle das Application.ThreadException Event wenn du ein eigenes Exception Handling (für unbehandelte Exceptions) willst.

        Comment


        • #5
          Hi,

          Winforms behandeln unbehandelte Ausnahmen ein wenig anders als erwartet. Info und Beispiele zB http://msdn.microsoft.com/de-de/libr...exception.aspx

          mfG Gü
          "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

          Comment


          • #6
            Super.. das war's
            Vielen Dank

            Comment

            Working...
            X