小编Old*_*oil的帖子

处理特定的和一般的Python异常?

我想捕获一个特定的异常并相应地处理它 - 然后我想继续并执行其他异常必须执行的泛型处理.

来自C背景,我以前可以使用gotos来达到预期的效果.

这是我目前正在做的,它工作正常:

try:
    output_var = some_magical_function()
except IntegrityError as zde:
    integrity_error_handling()
    shared_exception_handling_function(zde) # could be error reporting
except SomeOtherException as soe:
    shared_exception_handling_function(soe) # the same function as above
Run Code Online (Sandbox Code Playgroud)

Tldr:

即 - 是否有"Pythonic"方式执行以下操作:

try:
    output_var = some_magical_function()
except IntegrityError as zde:
    integrity_error_handling()
except ALLExceptions as ae: # all exceptions INCLUDING the IntregityError
    shared_exception_handling_function(ae) # could be error reporting
Run Code Online (Sandbox Code Playgroud)

注意:我知道finally子句 - 这不是为了整理(即关闭文件)·

python

5
推荐指数
2
解决办法
851
查看次数

无法在Windows Mobile 6上实现GetDeviceUniqueID

我使用的代码非常类似于以下Stack Overflow问题: 在PInvoke DLL'coredll.dll'中找不到入口点'GetDeviceUniqueID'

(为了后人的缘故,我的代码粘贴在这里):

[DllImport("coredll.dll")]
private extern static int GetDeviceUniqueID([In, Out] byte[] appdata,
                                            int cbApplictionData,
                                            int dwDeviceIDVersion,
                                            [In, Out] byte[] deviceIDOuput,
                                            out uint pcbDeviceIDOutput);



public static string GetDeviceID()
{
    string appString = "MyApp";
    byte[] appData = new byte[appString.Length];
    for (int count = 0; count < appString.Length; count++)
    {
        appData[count] = (byte)appString[count];
    }

    int appDataSize = appData.Length;
    byte[] DeviceOutput = new byte[20];
    uint SizeOut = 20;
    int i_rc = GetDeviceUniqueID(appData, appDataSize, 1, DeviceOutput, out SizeOut);

    string idString = "";
    for …
Run Code Online (Sandbox Code Playgroud)

c# windows-mobile .net-3.5

5
推荐指数
1
解决办法
700
查看次数

标签 统计

.net-3.5 ×1

c# ×1

python ×1

windows-mobile ×1