|
From: bpatton on 20 Apr 2008 15:46 I'm trying to define a macro to be able to pass to throw a character constant and some other values Here's what I'm defining #ifndef CR #define CR << "\n" #endif #ifndef FL #define FL << " (" << __FILE__ << ':' << __LINE__ << ")" #endif #ifndef SP #define SP << ' ' #endif #ifndef MSG #define MSG(m) string str(m) #endif Here's where I'm trying to use it: if (file.empty()) throw(MSG("Empty string recieved!") FL CR); I'm using MSVisual Express 2008 I need for the first element of of the macro to be a constant char as input to a string Then have the << from FL and CR to add teh file name and line number to the string then this will be caught by my catch section.
From: Ian Collins on 20 Apr 2008 17:54 bpatton wrote: > I'm trying to define a macro to be able to pass to throw a character > constant and some other values > > Here's what I'm defining > > #ifndef CR > #define CR << "\n" > #endif > #ifndef FL > #define FL << " (" << __FILE__ << ':' << __LINE__ << ")" > #endif > #ifndef SP > #define SP << ' ' > #endif > #ifndef MSG > #define MSG(m) string str(m) > #endif > > Here's where I'm trying to use it: > > if (file.empty()) throw(MSG("Empty string recieved!") FL CR); > Why don't you derive a class form a standard exception that include this additional information? You can then use a macro to construct an instance of this class. -- Ian Collins.
From: bpatton on 20 Apr 2008 19:17 On Apr 20, 4:54 pm, Ian Collins <ian-n...(a)hotmail.com> wrote: > bpatton wrote: > > I'm trying to define a macro to be able to pass to throw a character > > constant and some other values > > > Here's what I'm defining > > > #ifndef CR > > #define CR << "\n" > > #endif > > #ifndef FL > > #define FL << " (" << __FILE__ << ':' << __LINE__ << ")" > > #endif > > #ifndef SP > > #define SP << ' ' > > #endif > > #ifndef MSG > > #define MSG(m) string str(m) > > #endif > > > Here's where I'm trying to use it: > > > if (file.empty()) throw(MSG("Empty string recieved!") FL CR); > > Why don't you derive a class form a standard exception that include this > additional information? You can then use a macro to construct an > instance of this class. > > -- > Ian Collins.- Hide quoted text - > > - Show quoted text - ?? I don't have a clue what you just said
|
Pages: 1 Prev: initializing array with list Next: initialising built in types with curly braces |