From 97dc26efa6f2cdef07a2a59baec845ddc36ef75b Mon Sep 17 00:00:00 2001 From: ExcuseMi Date: Tue, 9 Aug 2016 20:44:40 +0200 Subject: [PATCH] Catch exception if pokemon could not be found. --- PogoLocationFeeder.GUI/Common/PokemonFilter.cs | 18 +++++++++++++----- PogoLocationFeeder/Helper/PokemonParser.cs | 7 +++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/PogoLocationFeeder.GUI/Common/PokemonFilter.cs b/PogoLocationFeeder.GUI/Common/PokemonFilter.cs index 2256abb..c58c6c8 100644 --- a/PogoLocationFeeder.GUI/Common/PokemonFilter.cs +++ b/PogoLocationFeeder.GUI/Common/PokemonFilter.cs @@ -9,6 +9,7 @@ using Newtonsoft.Json.Converters; using PogoLocationFeeder.Config; using PogoLocationFeeder.GUI.Models; +using PogoLocationFeeder.Helper; using POGOProtos.Enums; namespace PogoLocationFeeder.GUI.Common { @@ -59,13 +60,20 @@ public static void Load() { var set = GlobalSettings.PokekomsToFeedFilter; foreach (var s in set) { - var id = (PokemonId) Enum.Parse(typeof(PokemonId), s); - var img = new BitmapImage( + try + { + var id = PokemonParser.ParsePokemon(s, true); + var img = new BitmapImage( new Uri( - $"pack://application:,,,/PogoLocationFeeder.GUI;component/Assets/icons/{(int) id}.png", + $"pack://application:,,,/PogoLocationFeeder.GUI;component/Assets/icons/{(int)id}.png", UriKind.Absolute)); - img.Freeze(); - GlobalVariables.PokemonToFeedFilterInternal.Add(new PokemonFilterModel(id.ToString(), img, true)); + img.Freeze(); + GlobalVariables.PokemonToFeedFilterInternal.Add(new PokemonFilterModel(id.ToString(), img, true)); + } + catch (Exception e) + { + Log.Warn("Could not add pokemon to the filter" , e); + } } } } diff --git a/PogoLocationFeeder/Helper/PokemonParser.cs b/PogoLocationFeeder/Helper/PokemonParser.cs index 0b6a861..2a68b78 100644 --- a/PogoLocationFeeder/Helper/PokemonParser.cs +++ b/PogoLocationFeeder/Helper/PokemonParser.cs @@ -16,7 +16,7 @@ public class PokemonParser new HashSet {"Mime"}) }; - public static PokemonId ParsePokemon(string input) + public static PokemonId ParsePokemon(string input, bool throwException = false) { foreach (var name in Enum.GetNames(typeof(PokemonId))) { @@ -49,7 +49,10 @@ public static PokemonId ParsePokemon(string input) } } - + if (throwException) + { + throw new Exception($"No pokemon found with name {input}"); + } return PokemonId.Missingno; }