當我使用try catch exception
有這一段代碼,我得到以下錯誤:嘗試捕捉異常錯誤
"not all code paths return values"
我的代碼:
public System.Drawing.Image Scan()
{
try
{
const string formatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
WIA.CommonDialog scanDialog = new WIA.CommonDialog();
WIA.ImageFile imageFile = null;
imageFile = scanDialog.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType, WIA.WiaImageIntent.GrayscaleIntent,
WIA.WiaImageBias.MinimizeSize, formatJPEG, false, true, false);
WIA.Vector vector = imageFile.FileData;
System.Drawing.Image i = System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])vector.get_BinaryData()));
return i;
}
catch (COMException ce)
{
if ((uint)ce.ErrorCode == 0x800A03EC)
{
return ce;
}
}
因爲你的功能不明確返回值。 'if((uint)ce.ErrorCode == 0x800A03EC)'如果這不是真的,那麼你的catch塊不會返回... – 2014-09-30 16:08:15
[不是所有的代碼路徑都返回一個值]的可能重複(http:// stackoverflow .com/questions/4292067/not-all-code-paths-return-a-value) – 2014-09-30 16:11:57