remove custom exception

This commit is contained in:
bao-qian 2017-01-30 00:26:11 +00:00
parent 052048ad4c
commit 974efc55ac
12 changed files with 62 additions and 121 deletions

View File

@ -75,7 +75,7 @@ namespace Wox.Core.Plugin
}
catch (Exception e)
{
Log.Exception($"|Wox.Core.Plugin.JsonRPCPlugin.Query|Exception when query <{query}>", e);
Log.Exception($"|JsonRPCPlugin.Query|Exception when query <{query}>", e);
}
}
return null;
@ -123,39 +123,53 @@ namespace Wox.Core.Plugin
{
try
{
using (Process process = Process.Start(startInfo))
using (var process = Process.Start(startInfo))
{
if (process != null)
{
using (StreamReader reader = process.StandardOutput)
using (var standardOutput = process.StandardOutput)
{
string result = reader.ReadToEnd();
if (result.StartsWith("DEBUG:"))
var result = standardOutput.ReadToEnd();
if (string.IsNullOrEmpty(result))
{
MessageBox.Show(new Form { TopMost = true }, result.Substring(6));
return "";
}
if (String.IsNullOrEmpty(result))
{
using (StreamReader errorReader = process.StandardError)
using (var standardError = process.StandardError)
{
string error = errorReader.ReadToEnd();
if (!String.IsNullOrEmpty(error))
var error = standardError.ReadToEnd();
if (!string.IsNullOrEmpty(error))
{
throw new WoxJsonRPCException(error);
Log.Error($"|JsonRPCPlugin.Execute|{error}");
return string.Empty;
}
else
{
Log.Error("|JsonRPCPlugin.Execute|Empty standard output and standard error.");
return string.Empty;
}
}
}
return result;
else if (result.StartsWith("DEBUG:"))
{
MessageBox.Show(new Form {TopMost = true}, result.Substring(6));
return string.Empty;
}
else
{
return result;
}
}
}
else
{
Log.Error("|JsonRPCPlugin.Execute|Can't start new process");
return string.Empty;
}
}
}
catch (Exception e)
{
throw new WoxJsonRPCException(e.Message);
Log.Exception($"|JsonRPCPlugin.Execute|Exception for filename <{startInfo.FileName}> with argument <{startInfo.Arguments}>", e);
return string.Empty;
}
return null;
}
public void Init(PluginInitContext ctx)

View File

@ -184,12 +184,13 @@ namespace Wox.Core.Plugin
});
metadata.QueryCount += 1;
metadata.AvgQueryTime = metadata.QueryCount == 1 ? milliseconds : (metadata.AvgQueryTime + milliseconds) / 2;
return results;
}
catch (Exception e)
{
throw new WoxPluginException(pair.Metadata.Name, "QueryForPlugin failed", e);
Log.Exception($"|PluginManager.QueryForPlugin|Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
return new List<Result>();
}
return results;
}
public static void UpdatePluginMetadata(List<Result> results, PluginMetadata metadata, Query query)

View File

@ -43,31 +43,43 @@ namespace Wox.Core.Resource
private Language GetLanguageByLanguageCode(string languageCode)
{
Language language = AvailableLanguages.GetAvailableLanguages().FirstOrDefault(o => o.LanguageCode.ToLower() == languageCode.ToLower());
var lowercase = languageCode.ToLower();
var language = AvailableLanguages.GetAvailableLanguages().FirstOrDefault(o => o.LanguageCode.ToLower() == lowercase);
if (language == null)
{
throw new WoxI18nException("Invalid language code:" + languageCode);
Log.Error($"|Internationalization.GetLanguageByLanguageCode|Language code can't be found <{languageCode}>");
return AvailableLanguages.English;
}
else
{
return language;
}
return language;
}
public void ChangeLanguage(Language language)
{
if (language == null) throw new WoxI18nException("language can't be null");
string path = GetLanguagePath(language);
if (string.IsNullOrEmpty(path))
if (language != null)
{
path = GetLanguagePath(AvailableLanguages.English);
if (string.IsNullOrEmpty(path))
string path = GetLanguagePath(language);
if (!string.IsNullOrEmpty(path))
{
throw new Exception("Change Language failed");
Settings.Language = language.LanguageCode;
ResourceMerger.UpdateResource(this);
}
else
{
Log.Error($"|Internationalization.ChangeLanguage|Language path can't be found <{path}>");
path = GetLanguagePath(AvailableLanguages.English);
if (string.IsNullOrEmpty(path))
{
Log.Error($"|Internationalization.ChangeLanguage|Default english language path can't be found <{path}>");
}
}
}
Settings.Language = language.LanguageCode;
ResourceMerger.UpdateResource(this);
else
{
Log.Error("|Internationalization.ChangeLanguage|Language can't be null");
}
}

View File

@ -6,6 +6,7 @@ using System.Windows;
using Wox.Core.Plugin;
using Wox.Plugin;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
namespace Wox.Core.Resource
{
@ -54,7 +55,7 @@ namespace Wox.Core.Resource
}
else
{
throw new WoxPluginException(plugin.Metadata.Name, "Can't find plugin location.");
Log.Error($"|ResourceMerger.UpdatePluginLanguages|Can't find plugin path <{location}> for <{plugin.Metadata.Name}>");
}
}

View File

@ -1,19 +0,0 @@
namespace Wox.Infrastructure.Exception
{
/// <summary>
/// Base Wox Exceptions
/// </summary>
public class WoxException : System.Exception
{
public WoxException(string msg)
: base(msg)
{
}
public WoxException(string msg, System.Exception innerException)
: base(msg, innerException)
{
}
}
}

View File

@ -1,12 +0,0 @@
namespace Wox.Infrastructure.Exception
{
/// <summary>
/// Represent exceptions that wox can't handle and MUST close running Wox.
/// </summary>
public class WoxFatalException : WoxException
{
public WoxFatalException(string msg) : base(msg)
{
}
}
}

View File

@ -1,9 +0,0 @@
namespace Wox.Infrastructure.Exception
{
public class WoxHttpException :WoxException
{
public WoxHttpException(string msg) : base(msg)
{
}
}
}

View File

@ -1,9 +0,0 @@
namespace Wox.Infrastructure.Exception
{
public class WoxI18nException : WoxException
{
public WoxI18nException(string msg) : base(msg)
{
}
}
}

View File

@ -1,10 +0,0 @@
namespace Wox.Infrastructure.Exception
{
public class WoxJsonRPCException : WoxException
{
public WoxJsonRPCException(string msg)
: base(msg)
{
}
}
}

View File

@ -1,18 +0,0 @@
namespace Wox.Infrastructure.Exception
{
public class WoxPluginException : WoxException
{
public string PluginName { get; set; }
public WoxPluginException(string pluginName, string msg, System.Exception e)
: base($"{pluginName} : {msg}", e)
{
PluginName = pluginName;
}
public WoxPluginException(string pluginName, string msg) : base(msg)
{
PluginName = pluginName;
}
}
}

View File

@ -67,12 +67,6 @@
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Exception\ExceptionFormatter.cs" />
<Compile Include="Exception\WoxException.cs" />
<Compile Include="Exception\WoxFatalException.cs" />
<Compile Include="Exception\WoxHttpException.cs" />
<Compile Include="Exception\WoxI18nException.cs" />
<Compile Include="Exception\WoxJsonRPCException.cs" />
<Compile Include="Exception\WoxPluginException.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Hotkey\InterceptKeys.cs" />
<Compile Include="Hotkey\KeyEvent.cs" />

View File

@ -21,10 +21,6 @@ namespace Wox.Helper
Application.Current.MainWindow.Dispatcher.Invoke(() =>
{
Report((Exception)e.ExceptionObject);
if (!(e.ExceptionObject is WoxException))
{
Environment.Exit(0);
}
});
}