我有以下catch语句:
select distinct A from [dbo].[table] where A not in (
select A from [dbo].[table] where C <> 0)
这永远不会过滤掉我需要的异常和语句:
import pymba
import numpy
import cv2
import time
import os
Camera = None
Vimba = None
ID = "myID"
def GetCamera():
'''
Applies the Singleton pattern to create unique vimba and camera instances.
Thus those are only once created.
'''
global ID
global Camera
global Vimba
if Camera is None:
# Create vimba instance
Vimba = pymba.Vimba()
# Startup vimba
Vimba.startup()
# Get system object
System = Vimba.getSystem()
# Discover cameras
if System.GeVTLIsPresent:
System.runFeatureCommand("GeVDiscoveryAllOnce")
time.sleep(0.200)
# Assign camera
Camera = Vimba.getCamera(ID)
# Open camera
Camera.openCamera()
# Set acquisition modes
Camera.AcquisitionMode = "Continuous"
return Camera
def Shutdown():
'''
tears down the component
'''
global Vimba
if Vimba is not None:
Vimba.shutdown()
def Snapshot():
'''
Uses the global camera object to generate a new image.
'''
Camera = GetCamera()
# Start capture
Camera.startCapture()
# Assign frames
Frames = [Camera.getFrame() for _ in range(1)]
# Iterate each frame
for Frame in Frames:
# Announce frame
Frame.announceFrame()
# Queue frame capture
Frame.queueFrameCapture()
# Acquisition
Camera.runFeatureCommand("AcquisitionStart")
time.sleep(0.500)
Camera.runFeatureCommand("AcquisitionStop")
# Wait for frame buffer
Frame.waitFrameCapture()
# Convert image
Image = numpy.ndarray(buffer=Frame.getBufferByteData(),
dtype=numpy.uint8,
shape=(Frame.height, Frame.width, 1)
)
cv2.imshow("example", Image)
cv2.waitKey(0)
# Cleanup
Camera.endCapture()
Camera.revokeAllFrames()
Snapshot()
当我看到以下消息时,会导致编译器错误:“ C#编译器中的内部错误”(请参见下图)。
将其更改为以下内容即可:
catch (CustomException e) when (e.InnerException is MySqlException ex && ex.Number == 1062)
{
// handle duplicate inserts
}
谁能告诉我为什么第一次使用不起作用?这是此文档的一部分:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/is#-type-pattern-
这是我的dotnet --info结果
e.InnerException is MySqlException ex && ex.Number == 1062