{"record":{"id":"a5d09b9c9da134c9","repo":"cefsharp/CefSharp","slug":"this-is-an-exception-coming-from-c","errorCode":null,"errorMessage":"This is an exception coming from C#","messagePattern":"This is an exception coming from C#","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"info","filePath":"CefSharp.Example/JavascriptBinding/AsyncBoundObject.cs","lineNumber":24,"sourceCode":"using System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Linq;\nusing System.Net;\nusing System.Text;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing CefSharp.Web;\n\nnamespace CefSharp.Example.JavascriptBinding\n{\n    public class AsyncBoundObject\n    {\n        //We expect an exception here, so tell VS to ignore\n        [DebuggerHidden]\n        public void Error()\n        {\n            throw new Exception(\"This is an exception coming from C#\");\n        }\n\n        //We expect an exception here, so tell VS to ignore\n        [DebuggerHidden]\n        public int Div(int divident, int divisor)\n        {\n            return divident / divisor;\n        }\n\n        public string DivWithBlockingTaskCall(int dividend, int divisor)\n        {\n            var taskToWaitOn = ExecuteTaskBeforeDivision(dividend, divisor);\n            taskToWaitOn.Wait();\n            return taskToWaitOn.Result;\n        }\n\n        private async Task<string> ExecuteTaskBeforeDivision(int dividend, int divisor)\n        {","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Example/JavascriptBinding/AsyncBoundObject.cs#L6-L42","documentation":"This is a deliberately-thrown exception in the CefSharp.Example AsyncBoundObject.Error() method — demo code that shows how a C# method bound to JavaScript propagates exceptions back to JS. It is not a production error; it exists so the test suite and example pages can verify the error-handling pipeline between C# and JS.","triggerScenarios":"Calling the bound object's Error() method from JavaScript (e.g. CefSharp.AsyncBoundObj.error()). Triggered only in the example browser app.","commonSituations":"Running the CefSharp.Example project and invoking the test button/handler that calls this bound method. Not encountered in production apps that don't reference AsyncBoundObject.","solutions":["This is expected behavior in the example — do not treat it as a real bug.","If you copied AsyncBoundObject into your app, remove or replace the Error() method.","Use try/catch in JavaScript (await obj.error()) to handle bound-object exceptions in your own binding code."],"exampleFix":"// JavaScript caller\n// before\nawait CefSharp.BindObjectAsync('asyncBoundObj');\nawait asyncBoundObj.error();\n\n// after\ntry { await asyncBoundObj.error(); }\ncatch (e) { console.log('C# exception:', e); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// In JavaScript\ntry { await asyncBoundObj.error(); }\ncatch (e) { console.log('Handled expected C# error:', e); }","preventionTips":["Recognize this as intentional example code — do not ship AsyncBoundObject.Error().","Remove example bound objects from production projects.","Always try/catch JS calls to bound C# methods."],"tags":["example-code","js-binding","intentional","exception-demo"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}