我正在尝试捕获自定义异常,但是在以下情况下仍然会收到Exception 'CustomException' is never thrown in the corresponding try block
检查错误:
class CustomException extends Exception { }
class Test {
/**
* @throws CustomException
*/
public function willFail()
{
throw new CustomException('I failed');
}
}
$test = new Test;
try {
$test->willFail();
} catch (CustomException $e) {
echo $e->getMessage();
}
上面的示例正常工作,除了PhpStorm给我带来了检查错误。
我到处搜索,在不完全禁用检查的情况下无法找到解决方法。任何帮助将不胜感激!
答案 0 :(得分:2)
以防万一将来其他人自己遇到这个问题,我将发布该问题的解决方案。
此问题已通过在Option Explicit
Sub createHyperlinks()
Const wshName As String = "Sheet2"
Const FirstRow As Long = 1
Const hColumn As Variant = "A"
Const sAddr As String = "A1"
Const ttDisplay As String = "D3"
Const IfNot As String = "No Value"
Dim Exceptions As Variant
Exceptions = Array(wshName) ' add more?
Dim wb As Workbook: Set wb = ThisWorkbook
Dim wsH As Worksheet: Set wsH = wb.Worksheets(wshName)
Dim i As Long: i = FirstRow
Dim ws As Worksheet
'wsH.Columns(hColumn).Clear ' Maybe instead of the following 'Clear' line.
For Each ws In wb.Worksheets
wsH.Cells(i, hColumn).Clear
If IsError(Application.Match(ws.Name, Exceptions, 0)) _
And IsError(Application.Match(ws.Index, Exceptions, 0)) Then
If ws.Range(ttDisplay).Value <> "" Then
wsH.Hyperlinks.Add Anchor:=wsH.Cells(i, hColumn), _
Address:="", _
SubAddress:=ws.Name & "!" & sAddr, _
TextToDisplay:=ws.Range(ttDisplay).Value
Else
wsH.Cells(i, hColumn) = IfNot & " (" & ws.Name & ")"
End If
i = i + 1
End If
Next ws
End Sub
中将“调用树分析深度”更新为“ 1”来解决。单击“分析”选项卡,然后在那里更新设置。