I want to ask if there is a way to suppress misra warnings using a custom function without having to write \\ Misra Warning Suppression
(always the same derivation) everywhere.
I often use throw std::runtime_error("Custom Error")
on many places in my code. Unfortunately, I have to do misra warning suppression. So I have to add \\ Misra Warning Suppression
after every throw std::runtime_error("Custom Error");
. In the code it is like this: throw std::runtime_error("Custom Error"); \\ Misra Warning Suppression
. Since I literally have to use it everywhere with the same derivation, I thought about shortening it.
Here, the std::exception can be any error type. So I thought about using macros like this:
#define EXCEPTION_MISRA( TYPE, MESSAGE ) \
throw TYPE( MESSAGE) // Use Misra Suppression
int main()
{
EXCEPTION_MISRA( std::runtime_error, "Custom Error" );
return 0;
}
Unfortunately, macros are not really the yellow from the egg for my use case. Is there any way to do the same using functions? Kind of making your own xyz::throw function, where in the function the \\ Misra Warning Suppression
is added?
Thank you!
I don't use MISRA, but would a template work? Something like
called like so: