Unmanaged Exception Handling
#1
Posted 01 January 2011 - 06:36 AM
#2
Posted 01 January 2011 - 06:57 AM
#3
Posted 01 January 2011 - 08:45 AM
You should be able to catch unmanaged exception with a general catch block (a catch block without an exception type specified):Is it possible to catch an exception thrown in unmanaged code with managed code??
try { ... } catch { // Catches non-CLS exceptions }Unfortunately, you cannot access the exception details, you'd need runtime support for that (e.g. some special method). What unmanaged exceptions are you interested in? I don't think .NET Micro Framework is compiled with (C++) exceptions enabled.
#4
Posted 02 January 2011 - 05:25 PM
What unmanaged exceptions are you interested in?
I'm trying to make the N+ automatically reboot when the ethernet cable gets bumped and the unmanaged code crashes... Or any other time something goes terribly wrong - I want the unit to be able to automatically recover from various unanticipated error conditions.
#5
Posted 02 January 2011 - 05:27 PM
Hi Charles,
In a way. To pass an exception to managed code, set hr to one of the .NET MF exception constants. This will be converted into the appropriate Exception on the managed side...
Chris
That flew right over my head and possibly broke a window...
What is hr? Where would I find some good reading on .NET MF exception constraints?
#6
Posted 02 January 2011 - 07:18 PM
I'm trying to make the N+ automatically reboot when the ethernet cable gets bumped and the unmanaged code crashes... Or any other time something goes terribly wrong - I want the unit to be able to automatically recover from various unanticipated error conditions.
Would it be helpful if we exposed a SoftReboot and/or HardReboot method for those "something goes terribly wrong" cases?
You can also wire a GPIO to the RESET header and drive it low to reset the board.
Chris
#7
Posted 02 January 2011 - 07:26 PM
That flew right over my head and possibly broke a window...
What is hr? Where would I find some good reading on .NET MF exception constraints?
The official Microsoft reference to the porting guide is installed with the porting kit (.NET MF source).
Look for C:\MicroFrameworkPK_v4_1\Documentation\RCLPort.chm. Except follows.
RCLPort.chm > The .NET Micro Framework Porting Kit > Porting Kit Overviews > Adding Features to Your Port > Adding Features to the .NET Micro Framework by Interoperating with Unmanaged Code > Creating Interop APIs > Writing Your Interop Drivers
"Your stubs have an HRESULT reference parameter that they can use to pass error codes back to your C# interop methods. These are translated to exceptions that are thrown in the C# interop method. The following table lists the C++ error codes that are supported and their corresponding exceptions."
The table lists possible C++ error codes to return... For instance, setting hr to CLR_E_ARGUMENT_NULL results in the .NET MF runtime throwing a System.ArgumentNullException.
Chris
#8
Posted 03 January 2011 - 05:15 AM
Would it be helpful if we exposed a SoftReboot and/or HardReboot method for those "something goes terribly wrong" cases?
Chris
That would be of great help as it would prevent me from having to waste a GPIO.
#9
Posted 03 January 2011 - 06:14 AM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users