Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:29:38+00:00 2026-05-27T23:29:38+00:00

This is my generic exception and its base class, written in native C++: class

  • 0

This is my generic exception and its base class, written in native C++:

class DRAException : public std::exception {
public:
    DRAException( const std::string& what ) : std::exception( what.c_str() ) {}
    virtual ~DRAException( ){}
};

template<typename T>
class InvalidArgumentException : public DRAException{
    static std::string CreateErrorMessage( const std::string& argName, T value, boost::optional<T> min, boost::optional<T> max ){
        std::string& errorMessage = "Invalid argument value for " + argName + ": " + StringUtils::toString(value);
        if( min.is_initialized() )
            errorMessage += ". Min value: " + StringUtils::toString( min.get() );
        if( max.is_initialized() )
            errorMessage += ". Max value: " + StringUtils::toString( max.get() );
        return errorMessage;
    }
public:
    InvalidArgumentException( const std::string& argName, T value, boost::optional<T> min, boost::optional<T> max ) :
        DRAException( CreateErrorMessage(argName, value, min, max) ){ }
};

In a C++/CLI assembly, I define a macro which maps native exceptions to managed ones:

#define BEGIN_EXCEPTION_GUARDED_BLOCK \
    try {
#define END_EXCEPTION_GUARDED_BLOCK \
    \
    //Other catch clauses omitted for brevity's sake
    } catch( DRAExceptions::InvalidArgumentException ex ) { \
        throw gcnew System::ArgumentException( msclr::interop::marshal_as<System::String^>( ex.what() ) ); \
    }

And then I use it like this:

void MCImage::FindOptimalLut( Single% fWindow, Single% fLevel ) {
    BEGIN_EXCEPTION_GUARDED_BLOCK
    pin_ptr<Single> pWindow = &fWindow, pLevel = &fLevel;
    m_pNativeInstance->findOptimalLut( *pWindow, *pLevel );
    END_EXCEPTION_GUARDED_BLOCK
}

But when trying to build the last piece of code, I get this error:

Image.cpp(72): error C2955: 'DRAExceptions::InvalidArgumentException' : use of class template requires template argument list
4>          d:\svn.dra.workingcopy\mcommon\../CommonCppLibrary/CustomExceptions.h(50) : see declaration of 'DRAExceptions::InvalidArgumentException'
4>Image.cpp(72): error C2316: 'DRAExceptions::InvalidArgumentException' : cannot be caught as the destructor and/or copy constructor are inaccessible

I can’t specialize my templated class in the catch clause because that would defeat the purpose of catching all specializations regardless of type. As for the other error, both constructor and destructor are public, so I don’t get it. How can I work around this?

PS: I just started using the Boost libraries, so a Boost-specific solution is acceptable

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:29:39+00:00Added an answer on May 27, 2026 at 11:29 pm

    You’re trying to use a type template as if it was a type. It isn’t – only instantiations of the template are types.

    You can easily fix the problem in your case. Your class doesn’t need to be a template at all – only its constructor and the CreateErrorMessage helper function need to be templates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
How can I make this java generic cast ? public interface IField { }
When I try this with a generic class where this.value is T: if (this.value.GetType()
I'm trying to build a generic class to work with entities from EF. This
We have a legacy application that has a class like this : public class
What do you guys think about this for a generic singleton? using System; using
This is more of an generic XML Schema question, but if and how do
This may be a generic OOP question. I wanted to do a generic comparison
This is a very generic 'best practice' question, but here's an example. Let's say
This is kind of more generic question, isn't language-specific. More about idea and algorithm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.