异常处理开关:try{}catch(...){}

本文深入探讨了在VS2010中使用/EH开关来配置异常处理模型的方法,包括同步和异步异常处理的区别及应用实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

try{}catch(...){};这条语句在我们平时程序中会经常用到,当异常发生时能自动捕获。而对于程序异常时,我们可以通过参数
/EH{s|a}[c][-]

来设置要捕获对象。

Arguments
a

The exception-handling model that catches asynchronous (structured) and synchronous (C++) exceptions.

s

The exception-handling model that catches C++ exceptions only and tells the compiler to assume that extern C functions do throw an exception.

c

If used with s (/EHsc), catches C++ exceptions only and tells the compiler to assume that extern C functions never throw a C++ exception. /EHca is equivalent to /EHa.

Remarks

Use /EHs to specify the synchronous exception handling model (C++ exception handling without structured exception handling exceptions). If you use /EHs, then your catch clause will not catch asynchronous exceptions. Also, all objects in scope when the asynchronous exception is generated will not be destroyed even if the asynchronous exception is handled. Under /EHs, catch(...) will only catch C++ exceptions. Access violations and System.Exception exceptions will not be caught.

Use /EHa to specify the asynchronous exception handling model (C++ exception handling with structured exception handling exceptions). /EHa may result in a less performant image because the compiler will not optimize a try block as aggressively, even if the compiler does not see a throw.

Use /EHa if you want to catch an exception raised with something other than a throw. The following sample will generate an exception:

// compiler_options_EHA.cpp
// compile with: /EHa
#include <iostream>
#include <excpt.h>
using namespace std;

void fail() {   // generates SE and attempts to catch it using catch(...)
   try {
      int i = 0, j = 1;
      j /= i;   // This will throw a SE (divide by zero).
      printf("%d", j); 
   }
   catch(...) {   // catch block will only be executed under /EHa
      cout<<"Caught an exception in catch(...)."<<endl;
   }
}

int main() {
   __try {
      fail(); 
   }

   // __except will only catch an exception here
   __except(EXCEPTION_EXECUTE_HANDLER) {   
   // if the exception was not caught by the catch(...) inside fail()
      cout << "An exception was caught in __except." << endl;
   }
}

该开关位置:

VS2010中如下图

01-01 13:02:31.051 1676 4374 W AppOps : setUidMode() called with a mode inconsistent with runtime permission state, this is discouraged and you should revoke the runtime permission instead: uid=10110, switchCode=0, mode=4, permission=android.permission.ACCESS_BACKGROUND_LOCATION 01-01 13:02:31.052 1676 4374 E AppOpService: Blocked setUidMode call for runtime permission app op: uid = 10110, code = COARSE_LOCATION, mode = foreground, callingUid = 1000, oldMode = allow 01-01 13:02:31.052 1676 4374 E AppOpService: java.lang.RuntimeException 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.server.permission.access.appop.AppOpService.setUidMode(AppOpService.kt:272) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.server.appop.AppOpsCheckingServiceTracingDecorator.setUidMode(AppOpsCheckingServiceTracingDecorator.java:120) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.server.appop.AppOpsService.setUidMode(AppOpsService.java:2296) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.server.appop.AppOpsService.setUidMode(AppOpsService.java:2240) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.app.AppOpsManager.setUidMode(AppOpsManager.java:8715) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Permissions.setAppOpModeAsUser(Permissions.java:908) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Permissions.setAppOpUidModeAsUser(Permissions.java:885) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Permissions.grantPermissionAndAppOpAsUser(Permissions.java:373) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Permissions.grantSingleAsUser(Permissions.java:247) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Permissions.grantAsUser(Permissions.java:205) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.model.Role.grantAsUser(Role.java:867) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.service.RoleControllerServiceImpl.addRoleHolderInternal(RoleControllerServiceImpl.java:376) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.controller.service.RoleControllerServiceImpl.onGrantDefaultRoles(RoleControllerServiceImpl.java:163) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.LocalRoleController.lambda$grantDefaultRoles$1(LocalRoleController.java:56) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.LocalRoleController.$r8$lambda$ye-flP7Mf14AbTzwSmiTgndT6Cg(LocalRoleController.java:0) 01-01 13:02:31.052 1676 4374 E AppOpService: at com.android.role.LocalRoleController$$ExternalSyntheticLambda1.run(R8$$SyntheticClass:0) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.os.Handler.handleCallback(Handler.java:1027) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.os.Handler.dispatchMessage(Handler.java:108) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.os.Looper.loopOnce(Looper.java:298) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.os.Looper.loop(Looper.java:408) 01-01 13:02:31.052 1676 4374 E AppOpService: at android.os.HandlerThread.run(HandlerThread.java:85) 01-01 13:02:31.053 1676 6106 W PackageManager: package com.google.android.gms uid 10131 pid 5040 call SetEnabledSetting(com.google.android.gms component = com.google.android.gms.auth.proximity.phonehub.NotificationOptInActivity, 0, 0)
08-07
08-05 15:41:03.347 1192 1192 D BluetoothHidHost: Proxy object disconnected 08-05 15:40:56.240 1232 1232 I chatty : uid=1000(system) ctc.android.smart.terminal.settings identical 2 lines 08-05 15:40:56.242 1232 1232 W ViewRootImpl[MoreActivity]: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=490.63416, y[0]=411.8772, toolType[0]=TOOL_TYPE_MOUSE, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1100162, downTime=1098858, deviceId=5, source=0x2002 } 08-05 15:41:03.347 353 1309 I ActivityManager: Process com.android.bluetooth (pid 597) has died: psvc PER 08-05 15:41:03.347 353 353 D BluetoothManagerService: BluetoothServiceConnection, disconnected: com.android.bluetooth.btservice.AdapterService 08-05 15:41:03.348 353 405 W libprocessgroup: kill(-597, 9) failed: No such process 08-05 15:41:03.348 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.a2dp.A2dpService in 1000ms 08-05 15:41:03.348 353 415 E BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED(1) 08-05 15:41:03.348 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.btservice.AdapterService in 1000ms 08-05 15:41:03.348 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.avrcp.AvrcpTargetService in 11000ms 08-05 15:41:03.349 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.opp.BluetoothOppService in 11000ms 08-05 15:41:03.349 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.gatt.GattService in 11000ms 08-05 15:41:03.349 353 415 D BluetoothManagerService: MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED hasDevice:true mEnable:true 08-05 15:41:03.349 353 415 D BluetoothManagerService: Broadcasting onBluetoothServiceDown() to 5 receivers. 08-05 15:41:03.349 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.hid.HidDeviceService in 21000ms 08-05 15:41:03.349 353 1309 W ActivityManager: Scheduling restart of crashed service com.android.bluetooth/.hid.HidHostService in 20999ms 08-05 15:41:03.350 353 415 E BluetoothManagerService: Unable to call onBluetoothServiceDown() on callback #0 08-05 15:41:03.350 353 415 E BluetoothManagerService: android.os.DeadObjectException 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.os.BinderProxy.transactNative(Native Method) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.os.BinderProxy.transact(Binder.java:1129) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.bluetooth.IBluetoothManagerCallback$Stub$Proxy.onBluetoothServiceDown(IBluetoothManagerCallback.java:109) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at com.android.server.BluetoothManagerService.sendBluetoothServiceDownCallback(BluetoothManagerService.java:1356) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at com.android.server.BluetoothManagerService.access$4700(BluetoothManagerService.java:83) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at com.android.server.BluetoothManagerService$BluetoothHandler.handleMessage(BluetoothManagerService.java:1799) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.os.Handler.dispatchMessage(Handler.java:106) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.os.Looper.loop(Looper.java:193) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at android.os.HandlerThread.run(HandlerThread.java:65) 08-05 15:41:03.350 353 415 E BluetoothManagerService: at com.android.server.ServiceThread.run(ServiceThread.java:44) 08-05 15:41:03.350 353 415 D BluetoothAdapter: onBluetoothServiceDown: android.bluetooth.IBluetooth$Stub$Proxy@d412eff 08-05 15:41:03.350 1232 1232 D BluetoothHidHost: Proxy object disconnected 08-05 15:41:03.350 3205 3239 D BluetoothAdapter: onBluetoothServiceDown: android.bluetooth.IBluetooth$Stub$Proxy@f8f674f 08-05 15:41:03.351 1232 1232 D BluetoothHidHost: Unbinding service... 08-05 15:41:03.351 353 415 D BluetoothManagerService: Sending BLE State Change: ON > TURNING_OFF
08-07
16:05:30.999151 2502 23822 I cameraserver: OmojiManager.cpp: 125 isSupportOmoji: property version: 08-05 16:05:30.999158 2502 23822 I cameraserver: OmojiManager.cpp: 126 isSupportOmoji: property switch: 08-05 16:05:30.999196 2502 23822 I cameraserver: OmojiManager.cpp: 194 omoji support: packageName = com.oplus.camera, activityName = NULL, ret=0 08-05 16:05:30.999209 2502 23822 I cameraserver: OmojiManager.cpp: 125 isSupportOmoji: property version: 08-05 16:05:30.999212 2502 23822 I cameraserver: OmojiManager.cpp: 126 isSupportOmoji: property switch: 08-05 16:05:30.999230 2502 23822 I cameraserver: OmojiManager.cpp: 194 omoji support: packageName = com.oplus.camera, activityName = NULL, ret=0 08-05 16:05:30.999237 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4193 addRemovePackageName() APS2Omoji after set omoji whitelist,mSupportAps2Omoji = 0 08-05 16:05:30.999262 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999268 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999272 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4198 addRemovePackageName() trdPartyFBSupportability: 0, getTrdPartyFBSupportability(): 0, mSupportFwkOmoji: 0, mSupportAps2Omoji: 0 08-05 16:05:30.999284 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 4119 operator()() operator(): Unknown tag com.oplus.trdParty.isSupport.video.faceBeauty, ignoring 08-05 16:05:30.999309 2502 23822 I cameraserver: APSInterface.cpp: 105 updateAPSSwitch , fbEnable 1 08-05 16:05:30.999316 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 5082 getTrdPartyFBJsonValue() getTrdPartyFBJsonValue apkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1 08-05 16:05:30.999324 2502 23822 I cameraserver: OmojiManager.cpp: 100 getOmojiEnable,Line:100, mOmojiEnable:0 08-05 16:05:30.999328 2502 23822 I cameraserver: APSInterface.cpp: 143 updateAPSSwitch mNeedAPSProcess 0, mApkPropName: oplus.video.beauty.com.oplus.camera, prop value: -1, platform: pineapple, activityName: NULL, activitysupport: 0 mStreamNeedAPSProcess: 0 08-05 16:05:30.999789 2502 23822 D Camera3-Device: Set real time priority for request queue thread (tid 29608) 08-05 16:05:31.000201 2502 23822 D Camera3-Utils: Set regular priority for thread (tid 23822) 08-05 16:05:31.000260 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 556 afterEndConfigure() afterEndConfigure: 556, clear mFromExtension: 0 08-05 16:05:31.000265 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 562 afterEndConfigure() afterEndConfigure: 562, mFromExtension: 0 08-05 16:05:31.000274 2502 23822 I OplusCameraService: CameraServiceExtImpl.cpp: 575 afterEndConfigure() afterEndConfigure: com.oplus.camera not using cameraunit. 08-05 16:05:31.000518 26917 27181 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.000602 26917 27310 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001008 26917 27881 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001220 26917 27438 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001299 26917 27347 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.001906 26917 27347 I BpBinder: onLastStrongRef automatically unlinking death recipients: 08-05 16:05:31.002378 3384 6132 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1281 com.android.server.camera.OplusCameraStateBroadcast.notifyCameraState:52 com.android.server.camera.CameraServiceProxyExtImpl.extendNotifyCameraState:370 com.android.server.camera.CameraServiceProxy.updateActivityCount:1580 com.android.server.camera.CameraServiceProxy.-$$Nest$mupdateActivityCount:0 08-05 16:05:31.002519 26917 27005 W CameraUnit, StateCallback: onConfigured,android.hardware.camera2.impl.CameraCaptureSessionImpl@2a7688f 08-05 16:05:31.002547 26917 27005 E CameraUnit, CameraUnit_TRACE: traceBeginSection, msg: CameraUnit.CameraStartupPerformance.onCameraCaptureSessionConfigured 08-05 16:05:31.002566 26917 26995 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnit.CameraStartupPerformance.createCaptureSession 08-05 16:05:31.002629 26917 27005 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnit.CameraStartupPerformance.onCameraCaptureSessionConfigured 08-05 16:05:31.002636 26917 26995 E CameraUnit, CameraUnit_TRACE: traceEndSection, msg: CameraUnitCamera2ImplCreateSession 08-05 16:05:31.002705 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.002853 26917 26995 I CameraUnit, Camera2StateMachineImpl: setDeviceState, cameraName: rear_sat, mDeviceState: SESSION_CREATING -> SESSION_CONFIGURED 08-05 16:05:31.002900 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.002983 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003003 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003013 26917 26995 D CameraUnit, ConsumerImpl: onSessionConfigured, previewCaptureRequest: android.hardware.camera2.CaptureRequest@c68851b6 08-05 16:05:31.003026 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003055 26917 27005 I CameraUnit, Camera2Impl: PreviewRequestCallback, onCaptureFailed, fail reason: 1, sequenceId:2 08-05 16:05:31.003206 26917 26995 V CameraUnit, ConsumerImpl: onSessionConfigured, mbEnableUX: true, mbDebug3ASyncSession: false, aeReq: null 08-05 16:05:31.003310 26917 27002 E CameraUnit, CameraUnit_TRACE: traceBeginSection, msg: ConsumerImpl.onSessionConfigured 08-05 16:05:31.003324 26917 26995 D CameraUnit, ProducerImpl: onSessionConfigured 08-05 16:05:31.003576 26917 26985 I OCAM_OneCameraImpl: onSessionConfigured, mSessionCallback:ei.i$f@a62c618 上面高通日志解释
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值