Flash Player 10.1 Global Error Handling 全域錯誤處理

Flash Player 10.1 Global Error Handling 全域錯誤處理 « focus1921’s web development

Flash Player 10.1 Global Error Handling 全域錯誤處理

在debug version的Flash Player中,如果遇到沒有用try…catch…補捉的錯誤時,會跳出錯誤視窗來顯示錯誤訊息、堆疊…等資訊。
debug version flash player 錯誤訊息

debug version flash player 錯誤訊息

 

在Flash Player 10.1提供了Global Error Handling全域錯誤處理機制來避免這種情況。可以處理所有程式未補捉的錯誤。

 

01 // 時間軸程式
02  
03 // 全域(未補捉)錯誤錯理
04 function onUncaughtError(e:UncaughtErrorEvent):void
05 {
06  // 防止debug player跳出錯誤訊息
07  e.preventDefault();
08   
09  // 可以作其它事例如跳出訊息視窗等等...
10 }
11  
12 // 切換啟用或關閉全域錯誤處理
13 cbEnable.addEventListener(Event.CHANGE, onCBEnableChange);
14 function onCBEnableChange(e:Event):void
15 {
16  if (cbEnable.selected)
17  {
18   // 為全域(未補捉)錯誤註冊偵聽
19   loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
20  }
21  else
22  {
23   // 為全域(未補捉)錯誤移除偵聽
24   loaderInfo.uncaughtErrorEvents.removeEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onUncaughtError);
25  }
26 }
27  
28 btnThrowError.addEventListener(MouseEvent.CLICK, onBtnThrowErrorClick);
29 function onBtnThrowErrorClick(e:MouseEvent):void
30 {
31  // 擲出未補捉錯誤
32  var _strTest:String=null;
33  trace(_strTest.length);

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 6 + 4 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)