473,507 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET 2005 [C#/VB] Throwing exceptions in a DLL

balabaster
797 Recognized Expert Contributor
Hey all, this might seem somewhat remedial but I'm unable to find any documentation on it - it pertains to throwing exceptions within a DLL.

I've written a DLL that contains a bunch of classes. One of my methods validates the contents of a file and throws any necessary exceptions based on invalid content - I'm using a standard "throw new exception..." call ...the thing is, when my code reaches the line where the exception is thrown, my Visual Studio IDE hangs up on that line instead of the external call to my validate method.

A short conceptual example to demonstrate:

MyDLL content:
Expand|Select|Wrap|Line Numbers
  1. Public Class FileContent
  2. Public Function ValidateFile(ByVal FileName As String) As Boolean
  3.     If Not System.IO.File.Exists(FileName) Then 
  4.      Throw New IOException("File "& FileName & " doesn't exist.")
  5.     End If
  6. End Function
  7. End Class
  8.  
Second project that contains reference to DLL
Expand|Select|Wrap|Line Numbers
  1. Imports MyDLL
  2. Public Module Module1
  3. Sub Main()
  4.     Dim oFC As New FileContent
  5.     oFC.ValidateFile("C:\FileThatDoesntExist.txt")
  6. End Sub
  7. End Module
  8.  
So my IDE is actually pulling up the VB file that contains the DLL content and highlights the line in the ValidateFile instead of just hanging on the oFC.ValidateFile method line where the exception is thrown instead of the IDE hanging on the oFC.ValidateFile line in my calling application.

If someone is using my DLL, I don't want them to have access to my code if their file doesn't validate, I just want them to have access to the any exceptions that are raised...am I expecting too much of VS 2005 or is this possible?
Jan 2 '08 #1
3 1937
Plater
7,872 Recognized Expert Expert
Hmm, I have done this and it worked just fine for me.
Do you have debugging information turned on for you .DLL (it's under the project settings, on what to do durring a debug/release build)
Jan 2 '08 #2
balabaster
797 Recognized Expert Contributor
Hmm, I have done this and it worked just fine for me.
Do you have debugging information turned on for you .DLL (it's under the project settings, on what to do durring a debug/release build)
Okay, under my debug settings, I've got "Enable the Visual Studio hosting process" checked and nothing else.

Rereading my original post, I'm wondering if I wasn't clear...

Did it make sense that my VS IDE was actually opening the VB file that is contained in the DLL assembly and highlighting the line:
Expand|Select|Wrap|Line Numbers
  1. Throw New Exception("File "& FileName & " doesn't exist.")
When in fact it should be hanging up in my external application on:
Expand|Select|Wrap|Line Numbers
  1. oFC.Validate("C:\FileThatDoesntExist.txt")
At which point my IDE should highlight the oFC.Validate line in the external application and the error should read: "File C:\FileThatDoesntExist.txt doesn't exist."

Not sure if that came across in my first post so I'm not sure if what you're getting me to do is what I'm actually trying to achieve...
Jan 3 '08 #3
Plater
7,872 Recognized Expert Expert
Ahh, I thought it was the otherway around, that you WANTED to go into the DLL and it wasn't.
Debuging information is available for the DLL, so the IDE can navigate to the source code page.
I am about 90% certain that in an actual deployed situation, the compiler will not be able to enter into the source code because it will not exist.
Jan 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4661
by: Mark Oueis | last post by:
I've been struggling with this question for a while. What is better design? To design functions to return error codes when an error occures, or to have them throw exceptions. If you chose the...
21
4374
by: mihai | last post by:
People say that is a bad technique to throw exception from constructors; and that the solution would be to create a function _create_ to initialize an object. What about copy constructors? How...
3
1808
by: kaloianm | last post by:
Hi, Does someone know whether it is a bad practice to create exception objects through reflection and throw them? I want to use this in order to dynamically convert from an integer errorCode to...
15
3227
by: Sek | last post by:
Gurus, I am wondering whether it is right to throw an exception from a Property of an object. To get into it further, is it okay to throw exception during 'get' operation? I was searching...
11
2741
by: sternr | last post by:
Hey, I use the following code: try { //Some code that has an exception } catch (Exception ex) { if (ex.innerException!=null) {throw ex.innerException;} }
4
1222
by: Sridhar | last post by:
Hi, I would like to know the general procedure to throw exceptions. Lets say I have a datagrid in my webpage and I am pulling the data for my webpage using a function. The function accepts...
6
3541
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
4
1944
by: Jay Dee | last post by:
I have a query about throwing exceptions. To throw an exception I type something like: try { // do somthing } catch (ArgumentOutOfRangeException) {
9
5786
by: thagor2008 | last post by:
Is the behaviour of throwing exceptions in a unix signal handler defined? eg: void sighandler(int sig) { ... do something throw myobj; }
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.