Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

BUG: An exception does not propagate correctly to the calling function in a Windows Forms applicatio

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RalphTheExpert - 14 Nov 2005 12:52 GMT
This thread is a continuation of a thread with the Subject "Unhandled
exception - Different under debugger and non-debugger".
(http://www.dotnetnewsgroups.com/newsgroupthread.asp?ID=186902)

Oleg and Carl:

Carl wrote: "I would think the only fully sanitary, guaranteed to work
way would be to either terminate the program from inside the handler, or
intern the exception in an object and pass (a pointer to) that object
through a WM_APP window message where your message loop can unwrap it
and re-throw or otherwise handle the exception."

I?m pretty good when it comes to MFC and WTL. I am just learning how to
use the .Net environment and, frankly, there is a whole new gestalt here
that I?m missing. I am clueless as to whether a message pump even exists
in this environment.  I?m guessing that there probably is and it has
been buried deep so that mere mortals don?t have to mess with it.

So, Oleg, my question to you is, ?Does what Carl suggests solve the
problem??  If it does, what?s the right way to do it?

Fleshing out Carl?s remark, I assume that the proper way to do what he
says is to do a RegisterWindowMessage to get a unique message number and
to post a message. My problem is that I am clueless as to how to code a
handler to process the message.

Another question to you, Oleg, is that the article you cited
(http://support.microsoft.com/default.aspx?scid=kb;en-us;836674) seems
to be talking about this in terms of SEH rather than C++ exceptions.

Another point of confusion that I have is that the article you cited
says ?In Visual Studio .NET 2003, click Application Configuration File
under Template, and then click Open?. Well, I?m running 2003 and there
is no Application Configuration File under Template.  There?s a resource
template icon but no ?XML file? under it. Sigh.

I followed the procedure under 2002 (even though I?m running 2003). I
followed those instructions and, as far as I can tell, there are no
behavioral differences. Sigh.

I haven?t tried MS?s ?Another workaround for this problem is to use the
Application.OnThreadException handler? because I don?t understand what
they?re trying to accomplish.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Oleg Starodumov - 14 Nov 2005 13:32 GMT
> So, Oleg, my question to you is, "Does what Carl suggests solve the
> problem?"  If it does, what's the right way to do it?

Yes, it does, but only for native C++ exceptions, while your application
seems to use managed exceptions. Managed exceptions can be thrown/caught
across message pumps.

(In case of native exceptions, my solution would be to catch everything that
I know should be caught before it can potentially cross CRT boundaries
(that is, do not allow native C++ exceptions that are used by my code
to leave the message handlers). I would leave everything else to the default
just-in-time debugging mechanism).

> Another question to you, Oleg, is that the article you cited
> (http://support.microsoft.com/default.aspx?scid=kb;en-us;836674) seems
> to be talking about this in terms of SEH rather than C++ exceptions.

It is talking about managed exceptions. It applies to System::Exception
and types derived from it. Btw, how is your exception class (MyException) defined?

> Another point of confusion that I have is that the article you cited
> says "In Visual Studio .NET 2003, click Application Configuration File
> under Template, and then click Open". Well, I'm running 2003 and there
> is no Application Configuration File under Template.  There's a resource
> template icon but no "XML file" under it. Sigh.

Create the file manually, name it yourapp.exe.config and place it into the same
directory with yourapp.exe (substitute the real name, of course :)
The file should contain the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

This should change the behavior of your application when running without debugger
(your handler will be able to catch the exception).

Oleg
RalphTheExpert - 14 Nov 2005 17:40 GMT
Oleg:

[snip]

>It is talking about managed exceptions. It applies to System::Exception
>and types derived from it. Btw, how is your exception class (MyException) defined?

/* MyException.h */

#pragma once

#using <mscorlib.dll>

public __gc
class    MyException: public System::Exception
{
public:
   /*
       Constructors, private methods, and other stuff.

       Oleg, do you need/want the full class?
   */
}; /* class    MyException: System::Exception */

>> Another point of confusion that I have is that the article you cited
>> says "In Visual Studio .NET 2003, click Application Configuration File
[quoted text clipped - 13 lines]
>This should change the behavior of your application when running without debugger
>(your handler will be able to catch the exception).

Thanks!

Is it my imagination, but does it take a very long time for the
executable to load the first time it is loaded when I put in
myApp.exe.config?

>Oleg

Ralph

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.