Skip to content

Commit 92cf176

Browse files
committed
resolved #80
1 parent bab3c02 commit 92cf176

File tree

12 files changed

+85
-37
lines changed

12 files changed

+85
-37
lines changed

src/CatLib.Core.NetStandard/CatLib.Core.NetStandard.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
<Compile Include="..\CatLib.Core\Support\Events\IEvent.cs" Link="Support\Events\IEvent.cs" />
100100
<Compile Include="..\CatLib.Core\Support\Exception\AssertException.cs" Link="Support\Exception\AssertException.cs" />
101101
<Compile Include="..\CatLib.Core\Support\Exception\CodeStandardException.cs" Link="Support\Exception\CodeStandardException.cs" />
102+
<Compile Include="..\CatLib.Core\Support\Exception\LogicException.cs" Link="Support\Exception\LogicException.cs" />
102103
<Compile Include="..\CatLib.Core\Support\Exception\RuntimeException.cs" Link="Support\Exception\RuntimeException.cs" />
103104
<Compile Include="..\CatLib.Core\Support\FilterChain\FilterChain.cs" Link="Support\FilterChain\FilterChain.cs" />
104105
<Compile Include="..\CatLib.Core\Support\FilterChain\IFilterChain.cs" Link="Support\FilterChain\IFilterChain.cs" />

src/CatLib.Core/CatLib.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
<Compile Include="Support\Events\Event.cs" />
8383
<Compile Include="Support\Exception\AssertException.cs" />
8484
<Compile Include="Support\Exception\CodeStandardException.cs" />
85+
<Compile Include="Support\Exception\LogicException.cs" />
8586
<Compile Include="Support\Exception\RuntimeException.cs" />
8687
<Compile Include="Support\FilterChain\FilterChain.cs" />
8788
<Compile Include="Support\FilterChain\IFilterChain.cs" />

src/CatLib.Core/CatLib/Application.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public virtual void Init()
233233
/// <summary>
234234
/// 初始化
235235
/// </summary>
236-
/// <exception cref="RuntimeException">没有调用<c>Bootstrap(...)</c>就尝试初始化时触发</exception>
236+
/// <exception cref="CodeStandardException">没有调用<c>Bootstrap(...)</c>就尝试初始化时触发</exception>
237237
protected IEnumerator CoroutineInit()
238238
{
239239
if (!bootstrapped)
@@ -267,7 +267,7 @@ protected IEnumerator CoroutineInit()
267267
/// 注册服务提供者
268268
/// </summary>
269269
/// <param name="provider">注册服务提供者</param>
270-
/// <exception cref="RuntimeException">服务提供者被重复注册时触发</exception>
270+
/// <exception cref="LogicException">服务提供者被重复注册时触发</exception>
271271
public virtual void Register(IServiceProvider provider)
272272
{
273273
StartCoroutine(CoroutineRegister(provider));
@@ -277,14 +277,14 @@ public virtual void Register(IServiceProvider provider)
277277
/// 注册服务提供者
278278
/// </summary>
279279
/// <param name="provider">注册服务提供者</param>
280-
/// <exception cref="RuntimeException">服务提供者被重复注册时触发</exception>
280+
/// <exception cref="LogicException">服务提供者被重复注册时触发</exception>
281281
protected IEnumerator CoroutineRegister(IServiceProvider provider)
282282
{
283283
Guard.Requires<ArgumentNullException>(provider != null);
284284

285285
if (IsRegisted(provider))
286286
{
287-
throw new RuntimeException($"Provider [{provider.GetType()}] is already register.");
287+
throw new LogicException($"Provider [{provider.GetType()}] is already register.");
288288
}
289289

290290
if (Process == StartProcess.Initing)

src/CatLib.Core/Support/Container/BindData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public IBindData OnRelease(Action<IBindData, object> closure)
127127
Guard.NotNull(closure, nameof(closure));
128128
if (!IsStatic)
129129
{
130-
throw new RuntimeException($"Service [{Service}] is not Singleton(Static) Bind , Can not call {nameof(OnRelease)}().");
130+
throw new LogicException($"Service [{Service}] is not Singleton(Static) Bind , Can not call {nameof(OnRelease)}().");
131131
}
132132
lock (SyncRoot)
133133
{

src/CatLib.Core/Support/Container/Bindable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ internal void AddContextual(string needs, string given)
8585
}
8686
if (contextual.ContainsKey(needs))
8787
{
88-
throw new RuntimeException($"Needs [{needs}] is already exist.");
88+
throw new LogicException($"Needs [{needs}] is already exist.");
8989
}
9090
contextual.Add(needs, given);
9191
}
@@ -117,7 +117,7 @@ protected void GuardIsDestroy()
117117
{
118118
if (isDestroy)
119119
{
120-
throw new RuntimeException("Current bind has be mark Destroy.");
120+
throw new LogicException("Current bind has be mark Destroy.");
121121
}
122122
}
123123
}

src/CatLib.Core/Support/Container/Container.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void Tag(string tag, params string[] service)
193193
/// </summary>
194194
/// <param name="tag">标记名</param>
195195
/// <returns>将会返回标记所对应的所有服务实例</returns>
196-
/// <exception cref="RuntimeException"><paramref name="tag"/>不存在</exception>
196+
/// <exception cref="LogicException"><paramref name="tag"/>不存在</exception>
197197
/// <exception cref="ArgumentNullException"><paramref name="tag"/>为<c>null</c>或者空字符串</exception>
198198
public object[] Tagged(string tag)
199199
{
@@ -202,7 +202,7 @@ public object[] Tagged(string tag)
202202
{
203203
if (!tags.TryGetValue(tag, out List<string> services))
204204
{
205-
throw new RuntimeException($"Tag [{tag}] is not exist.");
205+
throw new LogicException($"Tag [{tag}] is not exist.");
206206
}
207207

208208
var result = new object[services.Count];
@@ -321,7 +321,7 @@ public bool IsAlias(string name)
321321
/// <param name="alias">别名</param>
322322
/// <param name="service">映射到的服务名</param>
323323
/// <returns>当前容器对象</returns>
324-
/// <exception cref="RuntimeException"><paramref name="alias"/>别名冲突或者<paramref name="service"/>的绑定与实例都不存在</exception>
324+
/// <exception cref="LogicException"><paramref name="alias"/>别名冲突或者<paramref name="service"/>的绑定与实例都不存在</exception>
325325
/// <exception cref="ArgumentNullException"><paramref name="alias"/>,<paramref name="service"/>为<c>null</c>或者空字符串</exception>
326326
public IContainer Alias(string alias, string service)
327327
{
@@ -330,7 +330,7 @@ public IContainer Alias(string alias, string service)
330330

331331
if (alias == service)
332332
{
333-
throw new RuntimeException($"Alias is same as service name: [{alias}].");
333+
throw new LogicException($"Alias is same as service name: [{alias}].");
334334
}
335335

336336
alias = FormatService(alias);
@@ -341,7 +341,7 @@ public IContainer Alias(string alias, string service)
341341
GuardFlushing();
342342
if (aliases.ContainsKey(alias))
343343
{
344-
throw new RuntimeException($"Alias [{alias}] is already exists.");
344+
throw new LogicException($"Alias [{alias}] is already exists.");
345345
}
346346

347347
if (!binds.ContainsKey(service) && !instances.ContainsKey(service))
@@ -414,7 +414,7 @@ public IBindData Bind(string service, Type concrete, bool isStatic)
414414
Guard.NotNull(concrete, nameof(concrete));
415415
if (IsUnableType(concrete))
416416
{
417-
throw new RuntimeException($"Bind type [{concrete}] can not built");
417+
throw new LogicException($"Bind type [{concrete}] can not built");
418418
}
419419
return Bind(service, WrapperTypeBuilder(service, concrete), isStatic);
420420
}
@@ -426,7 +426,7 @@ public IBindData Bind(string service, Type concrete, bool isStatic)
426426
/// <param name="concrete">服务实现</param>
427427
/// <param name="isStatic">服务是否静态化</param>
428428
/// <returns>服务绑定数据</returns>
429-
/// <exception cref="RuntimeException"><paramref name="service"/>绑定冲突</exception>
429+
/// <exception cref="LogicException"><paramref name="service"/>绑定冲突</exception>
430430
/// <exception cref="ArgumentNullException"><paramref name="concrete"/>为<c>null</c></exception>
431431
public IBindData Bind(string service, Func<IContainer, object[], object> concrete, bool isStatic)
432432
{
@@ -441,17 +441,17 @@ public IBindData Bind(string service, Func<IContainer, object[], object> concret
441441

442442
if (binds.ContainsKey(service))
443443
{
444-
throw new RuntimeException($"Bind [{service}] already exists.");
444+
throw new LogicException($"Bind [{service}] already exists.");
445445
}
446446

447447
if (instances.ContainsKey(service))
448448
{
449-
throw new RuntimeException($"Instances [{service}] is already exists.");
449+
throw new LogicException($"Instances [{service}] is already exists.");
450450
}
451451

452452
if (aliases.ContainsKey(service))
453453
{
454-
throw new RuntimeException($"Aliase [{service}] is already exists.");
454+
throw new LogicException($"Aliase [{service}] is already exists.");
455455
}
456456

457457
var bindData = new BindData(this, service, concrete, isStatic);
@@ -550,7 +550,7 @@ public object Call(object target, MethodInfo methodInfo, params object[] userPar
550550
/// <param name="service">服务名或别名</param>
551551
/// <param name="userParams">用户传入的构造参数</param>
552552
/// <exception cref="ArgumentNullException"><paramref name="service"/>为<c>null</c>或者空字符串</exception>
553-
/// <exception cref="RuntimeException">出现循环依赖</exception>
553+
/// <exception cref="LogicException">出现循环依赖</exception>
554554
/// <returns>服务实例,如果构造失败那么返回null</returns>
555555
public object Make(string service, params object[] userParams)
556556
{
@@ -651,7 +651,7 @@ public void ClearExtenders(string service)
651651
/// <param name="service">服务名或别名</param>
652652
/// <param name="instance">服务实例,<c>null</c>也是合法的实例值</param>
653653
/// <exception cref="ArgumentNullException"><paramref name="service"/>为<c>null</c>或者空字符串</exception>
654-
/// <exception cref="RuntimeException"><paramref name="service"/>的服务在绑定设置中不是静态的</exception>
654+
/// <exception cref="LogicException"><paramref name="service"/>的服务在绑定设置中不是静态的</exception>
655655
/// <returns>被修饰器处理后的新的实例</returns>
656656
public object Instance(string service, object instance)
657657
{
@@ -669,7 +669,7 @@ public object Instance(string service, object instance)
669669
{
670670
if (!bindData.IsStatic)
671671
{
672-
throw new RuntimeException($"Service [{service}] is not Singleton(Static) Bind.");
672+
throw new LogicException($"Service [{service}] is not Singleton(Static) Bind.");
673673
}
674674
instance = ((BindData)bindData).TriggerResolving(instance);
675675
}
@@ -938,7 +938,7 @@ public void Flash(Action callback, params KeyValuePair<string, object>[] service
938938
// 所以我们抛出一个异常来终止该操作。
939939
if (HasBind(service.Key))
940940
{
941-
throw new RuntimeException(
941+
throw new LogicException(
942942
$"Flash service [{service.Key}] name has be used for {nameof(Bind)} or {nameof(Alias)}.");
943943
}
944944
}
@@ -1162,7 +1162,6 @@ protected virtual object ResloveAttrClass(Bindable makeServiceBindData, string s
11621162
{
11631163
return result;
11641164
}
1165-
11661165
throw;
11671166
}
11681167
}
@@ -1332,11 +1331,11 @@ protected virtual UnresolvableException MakeUnresolvablePrimitiveException(strin
13321331
/// </summary>
13331332
/// <param name="service">当前服务名</param>
13341333
/// <returns>运行时异常</returns>
1335-
protected virtual RuntimeException MakeCircularDependencyException(string service)
1334+
protected virtual LogicException MakeCircularDependencyException(string service)
13361335
{
13371336
var message = $"Circular dependency detected while for [{service}].";
13381337
message += GetBuildStackDebugMessage();
1339-
return new RuntimeException(message);
1338+
return new LogicException(message);
13401339
}
13411340

13421341
/// <summary>
@@ -1368,7 +1367,7 @@ protected virtual void GuardUserParamsCount(int count)
13681367
{
13691368
if (count > 255)
13701369
{
1371-
throw new RuntimeException("Too many parameters , must be less or equal than 255");
1370+
throw new LogicException("Too many parameters , must be less or equal than 255");
13721371
}
13731372
}
13741373

@@ -1415,7 +1414,7 @@ protected virtual Type SpeculatedServiceType(string service)
14151414
/// <param name="makeServiceBindData">服务绑定数据</param>
14161415
/// <param name="makeServiceInstance">服务实例</param>
14171416
/// <returns>服务实例</returns>
1418-
/// <exception cref="RuntimeException">属性是必须的或者注入类型和需求类型不一致</exception>
1417+
/// <exception cref="LogicException">属性是必须的或者注入类型和需求类型不一致</exception>
14191418
protected virtual void AttributeInject(Bindable makeServiceBindData, object makeServiceInstance)
14201419
{
14211420
if (makeServiceInstance == null)
@@ -1521,7 +1520,7 @@ protected virtual Func<ParameterInfo, object> GetParamsMatcher(ref object[] user
15211520
/// <param name="baseParams">服务实例的参数信息</param>
15221521
/// <param name="userParams">输入的构造参数列表</param>
15231522
/// <returns>服务所需参数的解决结果</returns>
1524-
/// <exception cref="RuntimeException">生成的实例类型和需求类型不一致</exception>
1523+
/// <exception cref="LogicException">生成的实例类型和需求类型不一致</exception>
15251524
protected virtual object[] GetDependencies(Bindable makeServiceBindData, ParameterInfo[] baseParams, object[] userParams)
15261525
{
15271526
if (baseParams.Length <= 0)
@@ -1813,7 +1812,7 @@ private BindData MakeEmptyBindData(string service)
18131812
/// <param name="userParams">用户传入的构造参数</param>
18141813
/// <returns>服务实例,如果构造失败那么返回null</returns>
18151814
/// <exception cref="ArgumentNullException"><paramref name="service"/>为<c>null</c>或者空字符串</exception>
1816-
/// <exception cref="RuntimeException">出现循环依赖</exception>
1815+
/// <exception cref="LogicException">出现循环依赖</exception>
18171816
/// <exception cref="UnresolvableException">无法解决服务</exception>
18181817
/// <returns>服务实例</returns>
18191818
private object Resolve(string service, params object[] userParams)

src/CatLib.Core/Support/Container/MethodContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public IMethodBind Bind(string method, object target, MethodInfo methodInfo)
8080
{
8181
if (methodMappings.ContainsKey(method))
8282
{
83-
throw new RuntimeException($"Method [{method}] is already {nameof(Bind)}");
83+
throw new LogicException($"Method [{method}] is already {nameof(Bind)}");
8484
}
8585

8686
var methodBind = new MethodBind(this, container, method, target, methodInfo);
@@ -223,9 +223,9 @@ public void Flush()
223223
/// 生成一个方法没有找到异常
224224
/// </summary>
225225
/// <param name="method"></param>
226-
private RuntimeException MakeMethodNotFoundException(string method)
226+
private LogicException MakeMethodNotFoundException(string method)
227227
{
228-
return new RuntimeException($"Method [{method}] is not found.");
228+
return new LogicException($"Method [{method}] is not found.");
229229
}
230230
}
231231
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* This file is part of the CatLib package.
3+
*
4+
* (c) Yu Bin <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Document: http://catlib.io/
10+
*/
11+
12+
using System;
13+
14+
namespace CatLib
15+
{
16+
/// <summary>
17+
/// 代码逻辑异常
18+
/// </summary>
19+
[ExcludeFromCodeCoverage]
20+
public class LogicException : RuntimeException
21+
{
22+
/// <summary>
23+
/// 代码逻辑异常
24+
/// </summary>
25+
public LogicException()
26+
{
27+
28+
}
29+
30+
/// <summary>
31+
/// 代码逻辑异常
32+
/// </summary>
33+
/// <param name="message">异常消息</param>
34+
public LogicException(string message) : base(message)
35+
{
36+
}
37+
38+
/// <summary>
39+
/// 代码逻辑异常
40+
/// </summary>
41+
/// <param name="message">异常消息</param>
42+
/// <param name="innerException">内部异常</param>
43+
public LogicException(string message, Exception innerException) : base(message, innerException)
44+
{
45+
}
46+
}
47+
}

src/CatLib.Core/Support/SortSet/SortSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public TElement Current
142142
{
143143
return current.Element;
144144
}
145-
throw new RuntimeException($"Can not get {nameof(current)} element");
145+
throw new LogicException($"Can not get {nameof(current)} element");
146146
}
147147
}
148148

@@ -157,7 +157,7 @@ object IEnumerator.Current
157157
{
158158
return current.Element;
159159
}
160-
throw new RuntimeException($"Can not get {nameof(current)} element");
160+
throw new LogicException($"Can not get {nameof(current)} element");
161161
}
162162
}
163163

src/CatLib.Core/Support/Template/Managed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Extend(Func<TInterface> builder, string name = null)
5151

5252
if (extendBuilder.ContainsKey(name))
5353
{
54-
throw new RuntimeException($"Extend [{name}]({GetType()}) is already exists.");
54+
throw new LogicException($"Extend [{name}]({GetType()}) is already exists.");
5555
}
5656

5757
extendBuilder.Add(name, builder);
@@ -139,7 +139,7 @@ private Func<TInterface> GetExtend(string name)
139139

140140
if (!extendBuilder.TryGetValue(name, out Func<TInterface> result))
141141
{
142-
throw new RuntimeException($"Can not find [{name}]({GetType()}) Extend.");
142+
throw new LogicException($"Can not find [{name}]({GetType()}) Extend.");
143143
}
144144

145145
return result;

0 commit comments

Comments
 (0)