config/{Global,Block}: throw exception on parser error
This commit is contained in:
parent
696add259b
commit
8af75c78f8
|
@ -21,7 +21,6 @@
|
|||
#include "Block.hxx"
|
||||
#include "Parser.hxx"
|
||||
#include "Path.hxx"
|
||||
#include "system/FatalError.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
|
||||
|
@ -35,7 +34,7 @@ BlockParam::GetIntValue() const
|
|||
char *endptr;
|
||||
long value2 = strtol(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0)
|
||||
FormatFatalError("Not a valid number in line %i", line);
|
||||
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||
|
||||
return value2;
|
||||
}
|
||||
|
@ -47,7 +46,7 @@ BlockParam::GetUnsignedValue() const
|
|||
char *endptr;
|
||||
unsigned long value2 = strtoul(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0)
|
||||
FormatFatalError("Not a valid number in line %i", line);
|
||||
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||
|
||||
return (unsigned)value2;
|
||||
}
|
||||
|
@ -59,10 +58,10 @@ BlockParam::GetPositiveValue() const
|
|||
char *endptr;
|
||||
unsigned long value2 = strtoul(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0)
|
||||
FormatFatalError("Not a valid number in line %i", line);
|
||||
throw FormatRuntimeError("Not a valid number in line %i", line);
|
||||
|
||||
if (value2 <= 0)
|
||||
FormatFatalError("Number in line %i must be positive", line);
|
||||
throw FormatRuntimeError("Number in line %i must be positive", line);
|
||||
|
||||
return (unsigned)value2;
|
||||
}
|
||||
|
@ -72,9 +71,9 @@ BlockParam::GetBoolValue() const
|
|||
{
|
||||
bool value2;
|
||||
if (!get_bool(value.c_str(), &value2))
|
||||
FormatFatalError("%s is not a boolean value (yes, true, 1) or "
|
||||
"(no, false, 0) on line %i\n",
|
||||
name.c_str(), line);
|
||||
throw FormatRuntimeError("%s is not a boolean value (yes, true, 1) or "
|
||||
"(no, false, 0) on line %i\n",
|
||||
name.c_str(), line);
|
||||
|
||||
return value2;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include "Domain.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "system/FatalError.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -126,8 +126,8 @@ config_get_unsigned(ConfigOption option, unsigned default_value)
|
|||
const char *const s = param->value.c_str();
|
||||
value = strtol(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0 || value < 0)
|
||||
FormatFatalError("Not a valid non-negative number in line %i",
|
||||
param->line);
|
||||
throw FormatRuntimeError("Not a valid non-negative number in line %i",
|
||||
param->line);
|
||||
|
||||
return (unsigned)value;
|
||||
}
|
||||
|
@ -145,11 +145,12 @@ config_get_positive(ConfigOption option, unsigned default_value)
|
|||
const char *const s = param->value.c_str();
|
||||
value = strtol(s, &endptr, 0);
|
||||
if (endptr == s || *endptr != 0)
|
||||
FormatFatalError("Not a valid number in line %i", param->line);
|
||||
throw FormatRuntimeError("Not a valid number in line %i",
|
||||
param->line);
|
||||
|
||||
if (value <= 0)
|
||||
FormatFatalError("Not a positive number in line %i",
|
||||
param->line);
|
||||
throw FormatRuntimeError("Not a positive number in line %i",
|
||||
param->line);
|
||||
|
||||
return (unsigned)value;
|
||||
}
|
||||
|
@ -165,9 +166,9 @@ config_get_bool(ConfigOption option, bool default_value)
|
|||
|
||||
success = get_bool(param->value.c_str(), &value);
|
||||
if (!success)
|
||||
FormatFatalError("Expected boolean value (yes, true, 1) or "
|
||||
"(no, false, 0) on line %i\n",
|
||||
param->line);
|
||||
throw FormatRuntimeError("Expected boolean value (yes, true, 1) or "
|
||||
"(no, false, 0) on line %i\n",
|
||||
param->line);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue