Exception-handling problems

D

Daniel Wilson

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
 
N

Nick Malik

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
 
M

Morten Wennevik

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.
 
D

Daniel Wilson

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
 
N

Nick Malik

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 said:
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 said:
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
handle
a trying
to
 
D

Daniel Wilson

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 said:
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 said:
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 said:
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

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
 
N

Nick Malik

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 said:
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 said:
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 said:
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

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top