C # User Defined Exception Handling for Erroe from Dll get Exception was not handled by user code

I am working with a dynamic C # application that links all classes to the main application from the Dll files that I create separately, in these files, when I link my DLL file dynamically, the error handlers want to reset errors over the connection, since it was here, here what am i trying to do

I have a dll file with this code and a class on it

class clsGlobles {

public object dlststus = false; // dtabase file status

public clsGlobles()
{
    try
    {
        if (dlststus == true)
        {

        }
        else
        {
            throw new Exception("Some important files are missing - Please re-install the application"); //throw this as a error and stop running the program

        }
    }
    catch (Exception ex)
    {
        throw ex; //throw exception to the upper throw catch exception where i like to hand it
    //Evan i use throw; instead of throw ex; i get the same result
    }
}

      

and then i link this dll file using a dynamic method which works well but when i try to pass the user definition error i get the error as no exception and show the class inside the dll file i dont want to handle any exceptions in my classes in dll file, I just need to pass them to the next step and process them in the program in which I use them.

here is the code i am using it

private void frmMain_Load(object sender, EventArgs e)
{
    string tf = "";

            tf = Application.StartupPath + "\\clsGlobles.dll";
            try
            {
                Assembly asm = Assembly.LoadFrom(tf);
                AppDomain.CurrentDomain.Load(asm.GetName());
                Type type = asm.GetTypes().First(t => t.Name == "clsGlobles");
                glbls = Activator.CreateInstance(type);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString()); // the error i throw in inside the dll class should come here and i could handle it from here
            }

}  

      

enter image description here

and when I close the above error box and continue executing, it also shows something like this

enter image description here

-1


source to share


1 answer


I think I am getting the answer here when I link my dll in the application by reference and then use it as an object inside my application by a using

directive it works fine and allows me to use an exception throw

for the application statement throw catch

, but when it is added to the application dynamically it expects. that I will handle my exceptions inside the dll and solve that ever problem, it won't let me throw exceptions using throw new exception("err")

into the application



Evan a no error handling for this throw new exception

is ok, but he won't allow throw

in the catch block

0


source







All Articles