473,242 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Exception-handling problems

I am having exception-handling and stability problems with .NET. I will
have a block of managed code inside try...catch and will still get a generic
..NET exception box that will tell me which assemblies are loaded before
shutting down. In one case, some of my DB-accessing code didn't handle a
NULL value properly. But try...catch wouldn't catch the exception and keep
going. I'd just get the error message and then it would shut the
application down.

Does .NET have problems like this? Or am I doing something wrong? I can't
roll code like this out to our customers.

Elsewhere in the application, I am using an open-source .NET library that
extern's lots of functions. I am going back through that library trying to
add exception-handling, but if all it is is a lot of externs, I don't see
what I can do. Is a library like that inherently unstable?

Thanks
--
Daniel Wilson
Senior Software Solutions Developer
Embtrak Development Team
http://www.Embtrak.com
DVBrown Company
Jul 21 '05 #1
6 2296
Please post an example of code that is not working in exception handling.

Also, depending on how the library was written, there is nothing wrong with
calling external library functions. well-written libraries are likely to
raise their own errors at the proper places.

-- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am having exception-handling and stability problems with .NET. I will
have a block of managed code inside try...catch and will still get a generic .NET exception box that will tell me which assemblies are loaded before
shutting down. In one case, some of my DB-accessing code didn't handle a
NULL value properly. But try...catch wouldn't catch the exception and keep
going. I'd just get the error message and then it would shut the
application down.

Does .NET have problems like this? Or am I doing something wrong? I can't roll code like this out to our customers.

Elsewhere in the application, I am using an open-source .NET library that
extern's lots of functions. I am going back through that library trying to add exception-handling, but if all it is is a lot of externs, I don't see
what I can do. Is a library like that inherently unstable?

Thanks
--
Daniel Wilson
Senior Software Solutions Developer
Embtrak Development Team
http://www.Embtrak.com
DVBrown Company

Jul 21 '05 #2
Hi Daniel,

I suspect the most likely answer is that the try/catch block may not be
correctly set up. A code sample would help.

There are some untrapped exceptions that you can catch using
Application.TreadException before Application.Run.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #3
Here's a sample of the extern code. I'm wondering if
SuppressUnmanagedCodeSecurity is also suppressing some checking that would
enhance stability.
[DllImport("opengl32.dll", EntryPoint="glEnable"),
SuppressUnmanagedCodeSecurity, CLSCompliantAttribute(true)]

public static extern void glEnable (int cap);

Here's a sample of the error-handling code that's not catching the
exceptions.

try{

UpdateDataSet();

mailBoxWin->fillUserList(GetUsers());

mailBoxWin->updateDataSet(set);

mailBoxWin->refreshView();

mailBoxWin->Show();

}catch(Exception *E){

String *sE = new String("Unable to launch Mail UI\n");

sE = sE->Concat(sE,E->Source);

sE = sE->Concat(sE,E->Message);

throw new Exception(sE);

}

return true;

}

And here is fillUserList, called by the block above:

Public Sub fillUserList(ByVal users As ArrayList)

Try

newMsgWin.fillUserList(users)

Catch E As Exception

Throw New Exception("Failed to fill user list." & vbCrLf & E.Message)

End Try

End Sub

Thanks for ideas!

dwilson

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:bfMjd.585466$8_6.498363@attbi_s04...
Please post an example of code that is not working in exception handling.

Also, depending on how the library was written, there is nothing wrong with calling external library functions. well-written libraries are likely to
raise their own errors at the proper places.

-- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am having exception-handling and stability problems with .NET. I will
have a block of managed code inside try...catch and will still get a

generic
.NET exception box that will tell me which assemblies are loaded before
shutting down. In one case, some of my DB-accessing code didn't handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the
application down.

Does .NET have problems like this? Or am I doing something wrong? I

can't
roll code like this out to our customers.

Elsewhere in the application, I am using an open-source .NET library that extern's lots of functions. I am going back through that library trying

to
add exception-handling, but if all it is is a lot of externs, I don't see what I can do. Is a library like that inherently unstable?

Thanks
--
Daniel Wilson
Senior Software Solutions Developer
Embtrak Development Team
http://www.Embtrak.com
DVBrown Company


Jul 21 '05 #4
Hi Daniel,

Well, I'm not sure of the error you are getting. The blocks appear well
coded (it's a bit unusual to see to blocks of code, one in C++ and the other
in VB).
In both blocks, you appear to be catching all errors and re-issuing an
exception upstream with the offending exception encapsulated. While you've
broken a couple of best practices (handle the error locally, trap errors
using a specific error type, only raise ApplicationException or a derived
exception class, etc), I don't see any code that fails to trap the error.

You say that this code is running and, at a point when you don't expect to
get an error message, a message appears showing details of the error. Does
that error message include the strings "Unable to launch Mail UI" or "failed
to fill user list"? because, if it does, then you ARE trapping the error...
and then turning around and throwing another one.

Are you trapping again upstream from the first code snippet?

--- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:uN*************@TK2MSFTNGP11.phx.gbl...
Here's a sample of the extern code. I'm wondering if
SuppressUnmanagedCodeSecurity is also suppressing some checking that would
enhance stability.
[DllImport("opengl32.dll", EntryPoint="glEnable"),
SuppressUnmanagedCodeSecurity, CLSCompliantAttribute(true)]

public static extern void glEnable (int cap);

Here's a sample of the error-handling code that's not catching the
exceptions.

try{

UpdateDataSet();

mailBoxWin->fillUserList(GetUsers());

mailBoxWin->updateDataSet(set);

mailBoxWin->refreshView();

mailBoxWin->Show();

}catch(Exception *E){

String *sE = new String("Unable to launch Mail UI\n");

sE = sE->Concat(sE,E->Source);

sE = sE->Concat(sE,E->Message);

throw new Exception(sE);

}

return true;

}

And here is fillUserList, called by the block above:

Public Sub fillUserList(ByVal users As ArrayList)

Try

newMsgWin.fillUserList(users)

Catch E As Exception

Throw New Exception("Failed to fill user list." & vbCrLf & E.Message)

End Try

End Sub

Thanks for ideas!

dwilson

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:bfMjd.585466$8_6.498363@attbi_s04...
Please post an example of code that is not working in exception handling.

Also, depending on how the library was written, there is nothing wrong with
calling external library functions. well-written libraries are likely to raise their own errors at the proper places.

-- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a

generic
.NET exception box that will tell me which assemblies are loaded before shutting down. In one case, some of my DB-accessing code didn't
handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the
application down.

Does .NET have problems like this? Or am I doing something wrong? I

can't
roll code like this out to our customers.

Elsewhere in the application, I am using an open-source .NET library that extern's lots of functions. I am going back through that library
trying to
add exception-handling, but if all it is is a lot of externs, I don't

see what I can do. Is a library like that inherently unstable?

Thanks
--
Daniel Wilson
Senior Software Solutions Developer
Embtrak Development Team
http://www.Embtrak.com
DVBrown Company



Jul 21 '05 #5
I trap the errors all the way up. The error messages with which the program
crashes are not those I wrote. They are about not being able to accept a
NULL value.

I'm now investigating whether my problem has to do with multiple revisions
residing on my computer, and an older one being in the GAC.

dwilson
"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:u1pkd.321852$wV.123003@attbi_s54...
Hi Daniel,

Well, I'm not sure of the error you are getting. The blocks appear well
coded (it's a bit unusual to see to blocks of code, one in C++ and the other in VB).
In both blocks, you appear to be catching all errors and re-issuing an
exception upstream with the offending exception encapsulated. While you've broken a couple of best practices (handle the error locally, trap errors
using a specific error type, only raise ApplicationException or a derived
exception class, etc), I don't see any code that fails to trap the error.

You say that this code is running and, at a point when you don't expect to
get an error message, a message appears showing details of the error. Does that error message include the strings "Unable to launch Mail UI" or "failed to fill user list"? because, if it does, then you ARE trapping the error... and then turning around and throwing another one.

Are you trapping again upstream from the first code snippet?

--- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:uN*************@TK2MSFTNGP11.phx.gbl...
Here's a sample of the extern code. I'm wondering if
SuppressUnmanagedCodeSecurity is also suppressing some checking that would
enhance stability.
[DllImport("opengl32.dll", EntryPoint="glEnable"),
SuppressUnmanagedCodeSecurity, CLSCompliantAttribute(true)]

public static extern void glEnable (int cap);

Here's a sample of the error-handling code that's not catching the
exceptions.

try{

UpdateDataSet();

mailBoxWin->fillUserList(GetUsers());

mailBoxWin->updateDataSet(set);

mailBoxWin->refreshView();

mailBoxWin->Show();

}catch(Exception *E){

String *sE = new String("Unable to launch Mail UI\n");

sE = sE->Concat(sE,E->Source);

sE = sE->Concat(sE,E->Message);

throw new Exception(sE);

}

return true;

}

And here is fillUserList, called by the block above:

Public Sub fillUserList(ByVal users As ArrayList)

Try

newMsgWin.fillUserList(users)

Catch E As Exception

Throw New Exception("Failed to fill user list." & vbCrLf & E.Message)

End Try

End Sub

Thanks for ideas!

dwilson

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:bfMjd.585466$8_6.498363@attbi_s04...
Please post an example of code that is not working in exception handling.
Also, depending on how the library was written, there is nothing wrong

with
calling external library functions. well-written libraries are likely to raise their own errors at the proper places.

-- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
> I am having exception-handling and stability problems with .NET. I will > have a block of managed code inside try...catch and will still get a
generic
> .NET exception box that will tell me which assemblies are loaded before > shutting down. In one case, some of my DB-accessing code didn't handle
a
> NULL value properly. But try...catch wouldn't catch the exception and keep
> going. I'd just get the error message and then it would shut the
> application down.
>
> Does .NET have problems like this? Or am I doing something wrong?
I can't
> roll code like this out to our customers.
>
> Elsewhere in the application, I am using an open-source .NET library

that
> extern's lots of functions. I am going back through that library

trying to
> add exception-handling, but if all it is is a lot of externs, I

don't see
> what I can do. Is a library like that inherently unstable?
>
> Thanks
>
>
> --
> Daniel Wilson
> Senior Software Solutions Developer
> Embtrak Development Team
> http://www.Embtrak.com
> DVBrown Company
>
>



Jul 21 '05 #6
sorry I haven't been more helpful.

If you are still stuck, try posting the topmost try-catch block and the
error message you are getting.

Thanks,
--- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:O5**************@TK2MSFTNGP14.phx.gbl...
I trap the errors all the way up. The error messages with which the program crashes are not those I wrote. They are about not being able to accept a
NULL value.

I'm now investigating whether my problem has to do with multiple revisions
residing on my computer, and an older one being in the GAC.

dwilson
"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:u1pkd.321852$wV.123003@attbi_s54...
Hi Daniel,

Well, I'm not sure of the error you are getting. The blocks appear well
coded (it's a bit unusual to see to blocks of code, one in C++ and the

other
in VB).
In both blocks, you appear to be catching all errors and re-issuing an
exception upstream with the offending exception encapsulated. While

you've
broken a couple of best practices (handle the error locally, trap errors
using a specific error type, only raise ApplicationException or a derived
exception class, etc), I don't see any code that fails to trap the error.
You say that this code is running and, at a point when you don't expect to get an error message, a message appears showing details of the error.

Does
that error message include the strings "Unable to launch Mail UI" or

"failed
to fill user list"? because, if it does, then you ARE trapping the

error...
and then turning around and throwing another one.

Are you trapping again upstream from the first code snippet?

--- Nick

"Daniel Wilson" <d.******@embtrak.com> wrote in message
news:uN*************@TK2MSFTNGP11.phx.gbl...
Here's a sample of the extern code. I'm wondering if
SuppressUnmanagedCodeSecurity is also suppressing some checking that would enhance stability.
[DllImport("opengl32.dll", EntryPoint="glEnable"),
SuppressUnmanagedCodeSecurity, CLSCompliantAttribute(true)]

public static extern void glEnable (int cap);

Here's a sample of the error-handling code that's not catching the
exceptions.

try{

UpdateDataSet();

mailBoxWin->fillUserList(GetUsers());

mailBoxWin->updateDataSet(set);

mailBoxWin->refreshView();

mailBoxWin->Show();

}catch(Exception *E){

String *sE = new String("Unable to launch Mail UI\n");

sE = sE->Concat(sE,E->Source);

sE = sE->Concat(sE,E->Message);

throw new Exception(sE);

}

return true;

}

And here is fillUserList, called by the block above:

Public Sub fillUserList(ByVal users As ArrayList)

Try

newMsgWin.fillUserList(users)

Catch E As Exception

Throw New Exception("Failed to fill user list." & vbCrLf & E.Message)

End Try

End Sub

Thanks for ideas!

dwilson

"Nick Malik" <ni*******@hotmail.nospam.com> wrote in message
news:bfMjd.585466$8_6.498363@attbi_s04...
> Please post an example of code that is not working in exception

handling.
>
> Also, depending on how the library was written, there is nothing wrong with
> calling external library functions. well-written libraries are likely to
> raise their own errors at the proper places.
>
> -- Nick
>
> "Daniel Wilson" <d.******@embtrak.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
> > I am having exception-handling and stability problems with .NET.
I
will
> > have a block of managed code inside try...catch and will still get

a > generic
> > .NET exception box that will tell me which assemblies are loaded

before
> > shutting down. In one case, some of my DB-accessing code didn't

handle
a
> > NULL value properly. But try...catch wouldn't catch the exception

and keep
> > going. I'd just get the error message and then it would shut the
> > application down.
> >
> > Does .NET have problems like this? Or am I doing something wrong? I > can't
> > roll code like this out to our customers.
> >
> > Elsewhere in the application, I am using an open-source .NET library that
> > extern's lots of functions. I am going back through that library

trying
> to
> > add exception-handling, but if all it is is a lot of externs, I don't see
> > what I can do. Is a library like that inherently unstable?
> >
> > Thanks
> >
> >
> > --
> > Daniel Wilson
> > Senior Software Solutions Developer
> > Embtrak Development Team
> > http://www.Embtrak.com
> > DVBrown Company
> >
> >
>
>



Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
5
by: PCC | last post by:
I am using the Exception Managment Application Block on Windows Server 2003 Enterprise and .NET v1.1. If I use the block with an ASP.NET web wervice or in a web application I get the following...
2
by: Alex | last post by:
Hi. What would happen if an exception occurs inside a Finally block and at the same time inside the try another exception was thrown without been handled by any catch? Alejandro.
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
11
by: l.woods | last post by:
I want to set up my CATCH for a specific exception, but I really don't know which one of the multitude that it is. I am getting the exception now with Catch ex as Exception but I want to be...
3
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let...
2
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: ...
12
by: josh | last post by:
Hi I have this code: class Exception : public exception { public: Exception(string m="exception!") : msg(m) {} ~Exception() throw() {} const char* what() { return msg.c_str(); } private:
2
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.