2018-09-10 02:41:13 +02:00
|
|
|
// Copyright © 2015 The CefSharp Authors. All rights reserved.
|
2015-09-08 11:20:31 +09:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2018-09-10 02:41:13 +02:00
|
|
|
using System.Threading.Tasks;
|
2015-09-08 11:20:31 +09:00
|
|
|
|
2018-10-29 16:21:42 +10:00
|
|
|
namespace CefSharp.Example.JavascriptBinding
|
2015-09-08 11:20:31 +09:00
|
|
|
{
|
|
|
|
|
public class ExceptionTestBoundObject
|
|
|
|
|
{
|
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
|
private double DivisionByZero(int zero)
|
|
|
|
|
{
|
|
|
|
|
return 10 / zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
|
public double TriggerNestedExceptions()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
return DivisionByZero(0);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception innerException)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Nested Exception Invalid", innerException);
|
|
|
|
|
}
|
2018-09-10 02:41:13 +02:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2015-09-08 11:20:31 +09:00
|
|
|
{
|
|
|
|
|
throw new OperationCanceledException("Nested Exception Canceled", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
|
public int TriggerParameterException(int parameter)
|
|
|
|
|
{
|
|
|
|
|
return parameter;
|
|
|
|
|
}
|
2015-10-23 16:40:07 +09:00
|
|
|
|
|
|
|
|
public void TestCallbackException(IJavascriptCallback errorCallback, IJavascriptCallback errorCallbackResult)
|
|
|
|
|
{
|
|
|
|
|
const int taskDelay = 500;
|
|
|
|
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(taskDelay);
|
|
|
|
|
|
|
|
|
|
using (errorCallback)
|
|
|
|
|
{
|
|
|
|
|
JavascriptResponse result = await errorCallback.ExecuteAsync("This callback from C# was delayed " + taskDelay + "ms");
|
|
|
|
|
string resultMessage;
|
|
|
|
|
if (result.Success)
|
|
|
|
|
{
|
|
|
|
|
resultMessage = "Fatal: No Exception thrown in error callback";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
resultMessage = "Exception Thrown: " + result.Message;
|
|
|
|
|
}
|
|
|
|
|
await errorCallbackResult.ExecuteAsync(resultMessage);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-08 11:20:31 +09:00
|
|
|
}
|
|
|
|
|
}
|