Fehlerbehandlung im Parser vervollständigt
This commit is contained in:
@@ -56,15 +56,24 @@ namespace WorldOfPeacecraft
|
|||||||
if (IsCompletePackage ()) {
|
if (IsCompletePackage ()) {
|
||||||
Parse ();
|
Parse ();
|
||||||
}
|
}
|
||||||
// TODO Try-catch. IMPORTANT!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Parse ()
|
private void Parse ()
|
||||||
{
|
{
|
||||||
String[] aMessage = Enumerable.ToArray (Message);
|
string[] aMessage = Enumerable.ToArray (Message);
|
||||||
Block mainBlock = new Block (aMessage, 0, aMessage.Length - 1);
|
Message.Clear();
|
||||||
ProcessData (mainBlock);
|
try {
|
||||||
|
Block mainBlock = new Block (aMessage, 0, aMessage.Length - 1);
|
||||||
|
ProcessData (mainBlock);
|
||||||
|
} catch (ParsingException e) {
|
||||||
|
string errormsg = "Error while parsing message: " + e.Message + "\n";
|
||||||
|
errormsg += "Message:";
|
||||||
|
foreach (string line in errormsg) {
|
||||||
|
errormsg += "\n\t" + line;
|
||||||
|
}
|
||||||
|
Console.WriteLine(errormsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessData (Block parentBlock)
|
private void ProcessData (Block parentBlock)
|
||||||
@@ -153,6 +162,9 @@ namespace WorldOfPeacecraft
|
|||||||
Dragon dragon = MapDragon (block);
|
Dragon dragon = MapDragon (block);
|
||||||
backend.removeDragon (dragon);
|
backend.removeDragon (dragon);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
ThrowUnknownBlockException(deleteBlock, block);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,6 +197,7 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
private void ProcessAnswer (Block block)
|
private void ProcessAnswer (Block block)
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessResult (Block procBlock)
|
private void ProcessResult (Block procBlock)
|
||||||
@@ -359,7 +372,7 @@ namespace WorldOfPeacecraft
|
|||||||
huntable = true;
|
huntable = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ParsingException("Unknown mapcell-property '" + prop + "'");
|
throw new ParsingException("Unknown mapcell property '" + prop + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Tile(x,y,walkable, wall, forest, huntable, water);
|
return new Tile(x,y,walkable, wall, forest, huntable, water);
|
||||||
@@ -462,22 +475,48 @@ namespace WorldOfPeacecraft
|
|||||||
|
|
||||||
public string GetStringValue (string name)
|
public string GetStringValue (string name)
|
||||||
{
|
{
|
||||||
return Values [name];
|
try {
|
||||||
|
return Values [name];
|
||||||
|
} catch (ArgumentOutOfRangeException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetIntValue (string name)
|
public int GetIntValue (string name)
|
||||||
{
|
{
|
||||||
return int.Parse (Values [name]);
|
try {
|
||||||
|
return int.Parse (Values [name]);
|
||||||
|
} catch (ArgumentOutOfRangeException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not an integer (it was '" + Values [name] + "')", e);
|
||||||
|
} catch (OverflowException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into an integer (it was '" + Values [name] + "')", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long GetLongValue (string name)
|
public long GetLongValue (string name)
|
||||||
{
|
{
|
||||||
return long.Parse (Values [name]);
|
try {
|
||||||
|
return long.Parse (Values [name]);
|
||||||
|
} catch (ArgumentOutOfRangeException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' in block '" + Name + "' is not a long (it was '" + Values [name] + "')", e);
|
||||||
|
} catch (OverflowException e) {
|
||||||
|
throw new ParsingException("The parameter '" + name + "' in blo '" + Name + "' does not fit into a long (it was '" + Values [name] + "')", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetBoolValue (string name)
|
public bool GetBoolValue (string name)
|
||||||
{
|
{
|
||||||
return bool.Parse (Values [name]);
|
try {
|
||||||
|
return bool.Parse (Values [name]);
|
||||||
|
} catch (ArgumentOutOfRangeException e) {
|
||||||
|
throw new ParsingException ("The parameter '" + name + "' does not exist in block '" + Name + "'", e);
|
||||||
|
} catch (FormatException e) {
|
||||||
|
throw new ParsingException ("The parameter '" + name + "' in block '" + Name + "' is not a bool (it was '" + Values [name] + "')", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user