Answered by:
Can I create custom exception in c++ and then catch it in javascript code?

Question
-
I developed one metro app in javascript and another WinRT component in c++.
Also I declared a custom exception in c++ WinRT component.
How can i catch this custom exception in my javascript app?
Thanks for your help.Friday, January 27, 2012 10:15 AM
Answers
-
Hi Ring_ABC,
All Windows Runtime exceptions are ref classes which derive from Platform::Exception. When you throw an exception across the ABI boundary, you must throw one of these Exception types. You cannot derive your own type from Platform::Exception. To throw a custom exception, you can use COMException and supply a user-defined HRESULT.
please refer to http://msdn.microsoft.com/en-us/library/windows/apps/hh441561(v=vs.110).aspx for more details.
Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, January 27, 2012 4:31 PM
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 31, 2012 4:04 PM
Friday, January 27, 2012 1:44 PMModerator
All replies
-
Hi Ring_ABC,
All Windows Runtime exceptions are ref classes which derive from Platform::Exception. When you throw an exception across the ABI boundary, you must throw one of these Exception types. You cannot derive your own type from Platform::Exception. To throw a custom exception, you can use COMException and supply a user-defined HRESULT.
please refer to http://msdn.microsoft.com/en-us/library/windows/apps/hh441561(v=vs.110).aspx for more details.
Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, January 27, 2012 4:31 PM
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 31, 2012 4:04 PM
Friday, January 27, 2012 1:44 PMModerator -
So can you provide a little more detail?
For example, this is what I'm doing right now:
public: static void MyErrorClass::CheckErrorCode(int code) { if(code < 1) { throw ref new COMException(code); } }
But, what happens in C#, is the following, which is pretty much useless for my customers:
=======================
An exception of type 'System.Exception' occurred in CSMainDemo.exe but was not handled in user code
WinRT information: The text associated with this error code could not be found.
Additional information: The text associated with this error code could not be found.
If there is a handler for this exception, the program may be safely continued.
Monday, June 11, 2012 3:41 PM -
The RP contains a String constructor for FailureException. However using it, does not give me the string the calling app. Its still "Unknown failure" error text.Wednesday, June 13, 2012 9:04 AM
-
Have to pick this up again. How do the WinRT components from MSFT attach custom error messages? I tried RoOriginateError to no avail.Thursday, February 21, 2013 9:19 AM
-
The link referenced above:
http://msdn.microsoft.com/en-us/library/windows/apps/hh441561(v=vs.110).aspx
results in "This topic is no longer available".
I am very interested in this information, is it available anywhere else?
- Edited by Asher.Thuridion Thursday, May 28, 2015 11:59 PM
Thursday, May 28, 2015 11:00 PM