我寫在C#中的Kinect的應用程序,我有這樣的代碼如何忽略異常
try //start of kinect code
{
_nui = new Runtime();
_nui.Initialize(RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseColor);
// hook up our events for video
_nui.DepthFrameReady += _nui_DepthFrameReady;
_nui.VideoFrameReady += _nui_VideoFrameReady;
// hook up our events for skeleton
_nui.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(_nui_SkeletonFrameReady);
// open the video stream at the proper resolution
_nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
_nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
// parameters used to smooth the skeleton data
_nui.SkeletonEngine.TransformSmooth = true;
TransformSmoothParameters parameters = new TransformSmoothParameters();
parameters.Smoothing = 0.8f;
parameters.Correction = 0.2f;
parameters.Prediction = 0.2f;
parameters.JitterRadius = 0.07f;
parameters.MaxDeviationRadius = 0.4f;
_nui.SkeletonEngine.SmoothParameters = parameters;
//set camera angle
_nui.NuiCamera.ElevationAngle = 17;
}
catch (System.Runtime.InteropServices.COMException)
{
MessageBox.Show("Could not initialize Kinect device.\nExiting application.");
_nui = null;
}
我正在尋找一種方式,我的應用程序不會崩潰(異常被忽略不計)時,Kinect的是未連接。我又創建了另外一個問題here,但是這個解決方案並不適用於我的場合,因爲我被迫使用過時的sdk,沒有人可以解決這個問題,所以我嘗試使用不同的方法。我怎樣才能忽略這個異常?如果你想忽略所有的異常(我可以扭轉作出_nui自己以後的變化)
什麼異常被拋出要忽略?一目瞭然,上面的代碼看起來應該忽略在該代碼塊中拋出的任何'COMException',但沒有什麼可以說如果在其他地方訪問_nui時,可能不會拋出空引用異常。 – Chris
這實際上取決於例外情況。您只能「忽略」對您的代碼邏輯不重要的異常。 –
整個_nui點AFTER這部分代碼可以由我來處理(我已經想過了)如何重點是我需要我的應用程序來通過這部分代碼,無論我把什麼放在應用程序的catch括號中在崩潰(拋出異常)在那裏 –