Best way to store exception strings

  • Thread starter Thread starter Torben Laursen
  • Start date Start date
T

Torben Laursen

I handle errors in my code by using my own exception class that takes a
number as argument to the constructor, and that number puts a string into
the exception class. The user can then catch the class and display the
string to the user.
Now the strings are all stored inside a map inside the exception class.

But my number of strings are growing and having them all inside the
exception class seems as a bad idear.

Does anyone know a good way to store the strings? (PS I want them compiled
into the code)

Regards Torben
 
I handle errors in my code by using my own exception class that takes a
number as argument to the constructor, and that number puts a string into
the exception class. The user can then catch the class and display the
string to the user.
Now the strings are all stored inside a map inside the exception class.

But my number of strings are growing and having them all inside the
exception class seems as a bad idear.

Does anyone know a good way to store the strings? (PS I want them compiled
into the code)

Add the table as a static member to your exception class.
that way there will be only 1 instance of it, and your exception class
instances only need to store the number and / or the text pointer.

I assume that the table is fixed at compile time, so multiple concurrent
lookup operations should be threadsafe.

--

Kind regards,
Bruno.
(e-mail address removed)
Remove only "_nos_pam"
 
I like to have a function to look up the strings. For your problem, it
sounds like the function would have a switch statement and for each case it
will return a different string. This way, you won't have to spend any time
initializing the strings unless there is an actual exception.
 
Back
Top