strtol / strtod usage question

Take a look at this. I was reviewing some code and some questions popped into my mind.

First, I've used strtol many times but never have I seen someone pass a NULL for the second value which should be a char** for stopstring. If the conversion fails, will the program crash? Will an exception be thrown? Is this call to strtol correct? Is it ever appropriate to pass NULL for the char**?

Second, I do not believe strtol throws an exception at all. But this is more of a followup to the first question. If a valid char** was passed (like it should be in my opinion), could any kind of exception ever be thrown for that line of code? If so, what exception? I'm wondering if calls to c-run time functions should ever be contained in try catch blocks. I'm having a hard time deciding when to put code in a try catch block when dealing with these types of system library calls.

This is code I have seen and my thought is to go ahead and provide a stopstring and then provide error checking based on the value of the resulting stopstring and get rid of the try...catch blocks. Does anyone disagree with that?

try
{
lResultStore = strtol(argv[i+1], NULL, 10);
}
catch (...)
{
//error handling would go here
}
[1303 byte] By [kempofighter] at [2007-11-19 12:18:44]
# 1 Re: strtol / strtod usage question
Is it ever appropriate to pass NULL for the char**?
MSDN states that if endptr is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by endptr.

The way that I interpret this is that it's OK to pass NULL as the second argument (but then you wont know why it stopped).

- petter
wildfrog at 2007-11-9 0:47:43 >