Thread: Propagating errors from c# dll

  1. #1
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949

    Propagating errors from c# dll

    The main question is simple. I have a c# dll I created to act as a plugin for an access solution. What would be a proper OO design pattern for returning error information from the dll to the solution?

    I know I use to use things like SetLastError for dlls written in C, however this does not seem to be the optimum solution for an OO pattern. The basic setup is I have a class written in VBA which calls methods within the dll. The methods return true or false depending on whether or not they worked. I would like to be able to get more information as to the nature of the failure if the methods returned false however.

    Code:
    Interface IMyClass
    {
         bool  MyMethod();
    }
    Class MyClass : IMyClass
    {
         public bool myMethod()
         {
              if(MyOtherMethod() != null)
              {
                   return true;
              }
              else
              {
                   return false;
              }
         }
         private dataType MyOtherMethod()
         {
              try
              {
                   dosomething;
                   return dataType;
              }
              catch(someException e)
              {
                   //how do I return this information
                   return null;
              }
         }
    }
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I like to create a MethodResult class that gets returned. That class might have a bool property called Success.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    I like that idea thanks. So kind of like the OO spin on HRESULT. Thanks!
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two errors, help!
    By j.vick in forum C Programming
    Replies: 6
    Last Post: 03-28-2010, 12:41 AM
  2. Can someone please help me with my errors?
    By WinterInChicago in forum C++ Programming
    Replies: 9
    Last Post: 09-22-2006, 02:25 PM
  3. Can't see errors, can you?
    By stustu92 in forum C Programming
    Replies: 4
    Last Post: 02-01-2006, 06:11 AM
  4. errors.. errrors.. more errors
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-23-2002, 08:43 PM
  5. Dev and errors
    By Moffesto in forum C++ Programming
    Replies: 0
    Last Post: 06-22-2002, 12:17 AM