ã¯ããã«
ãã·ã¹ãã éçºã«ããã¦ä¾å¤å¦çã¯éè¦ãªãã¤ã³ãã§ããããã¾ãã«è»½è¦ããã¦ããã®ãç¾ç¶ã§ã¯ãªãã§ãããããæ¬ç¨¿ã§ã¯ãããã¾ã§ã®èè ã®éçºçµé¨ã®ä¸ããå¹ã£ãæ±ç¨çãªææ³ã説æãã¾ãã
ããã®è¨äºã¯ãç¾ããè¨è¨ãã§ã¯ãªããç¾å®çãªè¨è¨ããç¾å ´ã«é©ç¨ã§ãããã§ããã ãæéã®å°ãªããæ±ç¨çãªè¨è¨ããç®æãã¦ãã¾ãã
対象èªè
ãJ2EEéçºè ã»ã¢ã¼ããã¯ããç¹ã«æ¥åã·ã¹ãã ã®éçºç¾å ´ã®æ¹ã対象ã§ãã
å¿ è¦ãªç°å¢
ãæ¦å¿µã®èª¬æãä¸å¿ã§ãã®ã§ãéçºç°å¢ã¯å¿ è¦ããã¾ããã
ã¨ã©ã¼ã®åé¡
ãå®è£ æã«èæ ®ãã¹ãã¨ã©ã¼ã¯2ã¤ã«å¤§å¥ã§ãã¾ãã
- æ³å®å ã§ãã©ã³ã¶ã¯ã·ã§ã³ã®å®è¡éå§åã«ãã§ãã¯ããã¨ã©ã¼ã主ã«å ¥åã¨ã©ã¼ã
- ç°å¸¸ãªç¶æ ã¨ãã¦ãã©ã³ã¶ã¯ã·ã§ã³ã®ç¶è¡ãä¸å¯è½ãªã¨ã©ã¼ï¼ä¾å¤ï¼ã
ãåè ã«ã¤ãã¦ã¯ãä¾å¤ã使ãã¹ãã§ã¯ããã¾ãããå ¥åãã§ãã¯ã¨ã©ã¼ã表ç¾ããã«ã¯ãã¹ãã¼ã¿ã¹ã³ã¼ãã使ãã¹ãã§ããçç±ã¯æ¬¡ã®ã¨ããã§ãã
- 主ã«UIã絡ãã®ã§ãcatchå¥ã«UIå¦çãæ¸ããã¨ã«ãªã£ã¦ãã¾ããcatchå¥ã«ã¯æ¥åå¦çãæ¸ãã¹ãã§ã¯ãªãã
- ä¾å¤ã¯å¦çã³ã¹ããé«ãã®ã§ãæ£å¸¸å¦çã«çµã¿è¾¼ãã¹ãã§ã¯ãªãã
- å ¥åã¨ã©ã¼ã¯è¤æ°ã®çºçåå ãè¿ãå ´åãããããä¾å¤ã¯ä¸ã¤ã®çºçåå ããè¿ããªããä¾å¤ã¯ã©ã¹ãæ¡å¼µããã°å¯è½ã ããä¾å¤å¦çãè¤éåãã¹ãã§ã¯ãªãã
ãæ¬ç¨¿ã§æ±ãã®ã¯ãå¾è ã§ãã
ãä¾å¤ãçºçããå ´åã¨ã¯ãä¾ãã°ä»ã·ã¹ãã ã¨ã®ãã¼ã¿äº¤æã«ããã¦ããã©ã¼ããããã§ãã¯ã«å¼ã£ããã£ãå ´åãªã©ã§ãããã®ãããªä¾å¤ã¯ãéçºè ãä»»æã§ä¾å¤ãçæãthrowãã¾ãããã®ãããªä¾å¤ã«ã¯ã¦ã¼ã¶ã¼å®ç¾©ä¾å¤ã使ããã¨ã§ãä¾å¤å¦çãçµ±ä¸ããå½¢å¼ã§è¡ãã¾ãã
ä¾å¤ã¯ã©ã¹ãå®ç¾©ãã
ãAPIã§å®ç¾©ããã¦ããä¾å¤ã¯ã以ä¸ã®å±æ§ããæã¡ã¾ããã
- ã¡ãã»ã¼ã¸
- ã¹ã¿ãã¯ãã¬ã¼ã¹
ããããã·ã¹ãã éçºã§ã¯ãéç¨ç£è¦ã«å¿ è¦ãªã¡ãã»ã¼ã¸ã³ã¼ãããã°ã¬ãã«ãå¿ é ã§ããããããã§æ°ãã«ã¦ã¼ã¶ã¼å®ç¾©ã¯ã©ã¹ãä½æãã¾ãã
ãRuntimeException
ãç¶æ¿ããã¯ã©ã¹ã¯ãã¡ã½ããã®throwsãè¨è¿°ããå¿
è¦ãããã¾ãããä¾å¤ãä¸è¦§ãã以å¤ã«ã¯å½¹ã«ç«ããªãthrowsãç¡ããªããã¨ã§ãã½ã¼ã¹ãé常ã«ãã£ãããã¾ãã
ãã»ã¨ãã©ã®å ´åã¯ãã®ã¦ã¼ã¶ã¼å®ç¾©ä¾å¤ã¯ã©ã¹ä¸ã¤ã§ãäºè¶³ãã¾ããããå±æ§ã追å ãããå ´åã¯ãã¦ã¼ã¶ã¼å®ç¾©ä¾å¤ã®ãµãã¯ã©ã¹ãä½ãã¨ããã§ãããã
ä¾å¤å¦çãåºåºã¯ã©ã¹ã«ã¾ã¨ãã
ãä¾å¤å¦çã¨ãªãtryï½catchã¯ãå¦çã®å®è¡ãå¼ã³åºããæ ¹ã£ããã®é¨åã®ã¿ã«å®è£ ãã¾ããä¸è¬çãªJ2EEãã¬ã¼ã ã¯ã¼ã¯ãèãã¦ã¿ã¾ãããã
é層 | åé¡ | å¼ã³åºãå±¥æ´ | 説æ |
1 | ãµã¼ãã¬ãã | XXXServlet.doPost() | HTTPãªã¯ã¨ã¹ããå¦çããå ¥ãå£ã |
2 | ã³ã³ããã¼ã© | BLInvoker.invoke() | ãã¬ã¼ã ã¯ã¼ã¯ãããªã¯ã¨ã¹ããã©ã¡ã¿ããå¦çãã¹ããã¸ãã¯ãé¸æããå®è¡ãããMVCã¢ãã«ã®Controllerã«ãããã |
3 | æ¥åãã¸ãã¯ã®åºåºã¯ã©ã¹ | BlBase.execute() | æ¥åãã¸ãã¯ãã¹ã¦ã«å ±éããåå¦çãå¾å¦çãä¾å¤å¦ç(try ï½ catch)ããã®ã³ã°ãè¡ããMVCã¢ãã«ã®Modelã«ãããã |
4 | æ¥åãã¸ã㯠| BlCalc.execute() | ã¦ã¼ã¶ã¼å®ç¾©ã®æ¥åãã¸ãã¯ã |
5 | æ±ç¨å¦ç | CheckUtils.isValidData() | ã¦ã¼ã¶ã¼å®ç¾©ã®æ±ç¨å¦çã |
ãæ¥åãã¸ãã¯ãæ±ç¨å¦çã§çºçããä¾å¤ã¯ãã¾ã¨ãã¦åºåºã¯ã©ã¹ã§å¦çãã¾ããããã«ãããåæ¥åãã¸ãã¯å ã§åå¥ã«ä¾å¤å¦çãå®è£ ããå¿ è¦ã¯ãªããªãã¾ããã¾ããä¾å¤å¦çãåºåºã¯ã©ã¹ã«ã¾ã¨ã¾ããã¨ã§ããã®ã³ã°ãã¾ã¨ã¾ãã¾ãã
ãã®ã³ã°ã®ãã¤ã³ã
ãä¸è¬çã«ãã°ãåºåãããã¤ã³ãã¯ã次ã®ã¨ããã§ãã
åºåå 容 | åºåºã¯ã©ã¹å ã®ãã®ã³ã°ç®æ |
æ¥åãã¸ãã¯ã®éå§ã¡ãã»ã¼ã¸ | tryå¥ã®å é |
æ¥åãã¸ãã¯å ã§çºçããä¾å¤ã®ã¡ãã»ã¼ã¸ | catchå¥ |
æ¥åãã¸ãã¯ã®çµäºã¡ãã»ã¼ã¸ | finallyå¥ |
ããã®ã³ã°ãåºåºã¯ã©ã¹ã«ã¾ã¨ã¾ãã®ã§ãæ¥åãã¸ãã¯å ã§éå§ã¡ãã»ã¼ã¸ãªã©ããã®ã³ã°ããå¿ è¦ã¯ããã¾ããã
ãã°ã«åºåãã¹ãå 容
ããã°ã«åºåãã¹ãé ç®ã¯æ¬¡ã®ã¨ããã§ãã
é ç® | 説æ |
æå» | yyyy/MM/dd hh:MM:ss.SSSå½¢å¼ã§ã西æ¦ããããªç§ã¾ã§ãå®è¡æéãç¥ãããå ´åãããªç§ã¯å¿ é ã§ãã. |
ã¹ã¬ããçªå· | ã¹ã¬ããåºæã®çªå·ããã«ãã¹ã¬ããã¢ããªã±ã¼ã·ã§ã³ã§ã¯å¿ é ã§ãã |
ã¦ã¼ã¶ã¼ID | ã·ã¹ãã ã®å©ç¨è çªå·ãè¤æ°ã¦ã¼ã¶ã¼ã®ã¢ããªã±ã¼ã·ã§ã³ã§ã¯å¿ é ã§ãã |
ãã°ã¬ãã« | ãã°ã¬ãã«ã¯å®è£
段éãéç¨æ®µéã§ãã°ã®åºåéãå¶éããããã«è¨å®ãã¾ãã Log4jã®å ´åï¼fatal, error, warn, info, debug, trace |
ã¡ãã»ã¼ã¸ã³ã¼ã | ãã°ä¸è¡æ¯ã®åé¡ã³ã¼ãããããã¯ã¨ã©ã¼ã³ã¼ãã |
ä»»æã¡ãã»ã¼ã¸ | ã¨ã©ã¼ã¡ãã»ã¼ã¸ãªã©ãæ¥æ¬èªã®èª¬æã |
ã¹ã¿ãã¯ãã¬ã¼ã¹ | ä¾å¤çºçç®æã¾ã§ã®å¼ã³åºãé層ã |
ããã«ãã¹ã¬ããã»è¤æ°ã¦ã¼ã¶ã¼ã®ã·ã¹ãã ï¼ç¹ã«Webã¢ããªï¼ã§ã¯ãã¹ã¬ããçªå·ã¨ã¦ã¼ã¶ã¼IDã¯å¿ ãåºåãã¦ãã ãããããããªããã°ãã¦ã¼ã¶ã¼ãã¨ã®å¦çããã°ã§è¿½ããã¨ãã§ãã¾ããã
ã以ä¸ã®é ç®(ã¹ã¿ãã¯ãã¬ã¼ã¹ãé¤ã)ãã1ã¤ã®ãã°ãã¡ã¤ã«ã«åºåãã¾ããã¹ã¿ãã¯ãã¬ã¼ã¹ã¯æ¨æºã¨ã©ã¼åºåã«åºåãã¾ãã
æå¾ã«
ãããã¾ã§ã§ãã©ã®ãããªææ³ããæã¡ã§ããããï¼ ããèãã¦è¨è¨ãè¡ãéçºè ãªããããªãã ãå½ããåã®ãã¨ã°ãããããªãããã¨æãã§ããããã§ãããèè ã®çµé¨ã§ã¯ããããªãã¨ãããã¾ããã
- ãã¸ãã¯ã®ä¸ã«try ï½ catchãæ£ãã°ããããä¾å¤å¦çãçµ±ä¸ããã¦ããªãããã°ã«ä¾å¤ãåºåããªãã誤ã£ããã©ã¼ãããã§åºåãããä¸åº¦ã®ä¾å¤ã§è¤æ°åã¹ã¿ãã¯ãã¬ã¼ã¹ãåºåããããªã©ã
- ãã¹ã¦ã®ã¯ã©ã¹ã«éå§ã»çµäºã¡ãã»ã¼ã¸ã®ãã®ã³ã°ãå®è£ ããã大éã«ãã°ãåºåããããã¤ãããã©ã¼ãã³ã¹ãé常ã«æªãã
- ãã°ã«ã¦ã¼ã¶ã¼IDãåºåãããªãã®ã§ã誰ã®æä½ã§ã¨ã©ã¼ãçºçããã®ãããããªãã
ããããªåæ©çãªåé¡ããå®ã¯ããªãã®éçºç¾å ´ã§çºçãã¦ãã¾ããå½ããåã®ãã¨ãªã®ã«æå¤ã¨ã¾ã¨ã¾ã£ãè³æãç¡ãã£ãã®ã§ãã¾ã¨ãã¦å ¬éãããã¨ã«ãã¾ããã
ãä¾å¤å¦çã¨ãã®ã³ã°ã¯ãè¨è¨ã»éçºæ®µéã§ã¯æãæããã¡ã§ãããããã®ãã次第ã§ãéç¨éå§å¾ã®é害ã®åæã¹ãã¼ãã¨å®å®æ§ãå¤ãã£ã¦ãã¾ããæ¬ç¨¿ã§ããµã¼ã管çè ã®ç¡ç æéãå°ãã§ã確ä¿ã§ããã°ã幸ãã§ãã
質åã¨åç
ãçæ§ããå¯ãããã質åã«åçãããã¨æãã¾ãã
No. | Q | A |
1 | ãä¾å¤å¦çã»ãã®ã³ã°ãåºåºã¯ã©ã¹ã«ã¾ã¨ãããã¨ã®ãã¨ã§ãããæè¿ã®J2EEã§ã¯åºåºã¯ã©ã¹ã«å¦çãã¾ã¨ãããããAOPã使ã£ã¦å¦çãæã¿è¾¼ããã¨ã主æµã«ãªã£ã¦ããã®ã§ã¯ãªãã§ããããï¼ | AOPã使ãããªãã°ãã¨ããåæã§ãã£ãããéãã ã¨æãã¾ãããã ããå®éã«ã¯AOPãç¾å ´ã®éçºè ã使ãããã¨ã¯å°ãªãã®ãç¾ç¶ã§ããAOPã使ãããã®ã©ã¤ãã©ãªã¯ããªã¼ã®ãã®ãå¤ããããªã¼ã¨ããã ãã§ä½¿ç¨ãæå¦ããã¾ããã¾ããAOPãç解ãã¦ãã人ã°ããã§ã¯ããã¾ãããAOPã使ã£ã¦ããã§ããï¼ãã¨èãã¦ãããããªããã®ããããªããã®ä½¿ããªããã¨ããåå¿ãè¿ãã§ãããã |
2 | ãã®ã³ã°ã®çµäºå¦çãfinallyå¥ã«è¨è¿°ããç°å¸¸çºçæã«ãæ£å¸¸ã«çµäºãããã®ããã«è¦ããªãã§ãããããç§ãè¨è¨ããã®ã§ããã°æ£å¸¸çµäºã¯returnæãå®è¡ãããå¾ã«å®è¡ããããã«AOPã使ã£ã¦å®è£ ãã¾ãã | ã©ãã§å¦çãè½ã¡ããã¯ã¹ã¿ãã¯ãã¬ã¼ã¹ãããããã¾ããfinallyå¥ã§å¿ ãåºãããã«ããªãå ´åãæ確㫔å¦çãåºã”ãã¨ããããã«ããã¨æãã¾ããã好ã¿ã®åé¡ããããã¾ããã |
3 | æ¨æºã¨ã©ã¼åºåã«åºåããã®ã¯ãªãã§ããï¼ããããããã¡ã¤ã«ã«èç©ããã»ããå¾ã§èª¿æ»ãããããªãã§ããï¼æ¨æºã¨ã©ã¼åºåããããã®ã¯è¨å®ã«ãã£ã¦ã¯ãã®ã¾ã¾ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºããã¾ããã³ã³ã½ã¼ã«ã«åºåããã¦ãã¾ã£ããã©ããã£ã¦åå ã調æ»ããã®ã§ããï¼ | æ¨æºã¨ã©ã¼åºåã¯ç¬ç«ãããã¡ã¤ã«ã«åºåããããã¨ããã®ã大åæã§ããæ¨æºã¨ã©ã¼åºåãã³ã³ã½ã¼ã«ã®ã¾ã¾ãã¨ããæ¥åã·ã¹ãã ã¯ããããªããå¿ ãç¬ç«ãããã¡ã¤ã«ã«åºåããããã¨èãã¦ãã¾ããæ¨æºã¨ã©ã¼åºåã¯Javaã§ä½ãããã·ã¹ãã å ¨ã¦ã«ç¨æããã¦ããã®ã§ãè¨è¨ãçµ±ä¸ã§ããã¨ããç¹ã§æå©ã§ããåºåãã©ã¼ãããã¯ãSystem.setErr()ã§ã«ã¹ã¿ãã¤ãºããPrintStreamã¯ã©ã¹ã使ããã¨ã«ããå®ç¾ãã¾ãã |
4 | ã³ã³ããã¼ã©ãåºåºã¯ã©ã¹ã®executeãå¼ã³åºããåºåºã¯ã©ã¹ã®executeã®tryãããã¯ã®ä¸ã§ãæ´¾çã¯ã©ã¹ã®executeãå¼ã°ããã®ã§ããããï¼ãããã¯ã³ã³ããã¼ã©ãå¼ã³åºãã®ã¯ãåºåºã¯ã©ã¹ã§å®ç¾©ãããä½ãå¥ã®ã¡ã½ããã§ãã£ã¦ããã®ã¡ã½ããã®tryãããã¯ã®ä¸ã§ãï¼ãªã¼ãã©ã¤ããããï¼executeãå¼ã³åºãã®ã§ããããï¼ | ã©ã¡ããããããã¨æãã¾ããè¨äºä¸ã®å¼ã³åºãä¾ã¯åè ã«ãããã¾ããããã§è¨ãããäºã¯ãåºåºã¯ã©ã¹ã«ã¾ã¨ããã¹ããã¨ããé¨åã§ããã®ã¯ã©ã¹å³ã¯ããã¾ã§ãµã³ãã«ã¨ãèããã ããã |
5 | RuntimeExceptionãExtendsãã¦ãã¾ããä»ã®ä¾å¤ã¯ã©ã¹ï¼ErrorãExceptionï¼ãç¶æ¿ããã¦ã¼ã¶å®ç¾©ä¾å¤ãè¨è¨ãããã¨ã¯å®éã¯ããã®ã§ããããï¼ã使ãåããªã©ãã©ããããããã»ã»ã | Errorã¯ã·ã¹ãã ãå ¨ãåä½ã§ããªããããªç°å¸¸ã®éã«ä½¿ãã¾ããã¾ãé常ã®ç¨éã§ã¯ä½¿ããã¨ã¯ããã¾ãããExceptionã¯ãã使ãã¾ãããthrows宣è¨ãå¿ è¦ã§ãã½ã¼ã¹ã®throws宣è¨ãè¥å¤§åããæå¾ã¯ç®¡çä¸è½ã«ãªãå±éºãããã¾ãã使ãåãã§ãããæ¥åã¨ã©ã¼ï¼ã¢ããªã¬ãã«ã®ç¶è¡å¯è½ãªæ³å®å ã®ã¨ã©ã¼ãä¾ãã°ä¸æ£ãªå ¥åãã¼ã¿ãæä½ã¨ã©ã¼ï¼ã¯RuntimeExceptionãä½ã¬ãã«ï¼¡ï¼°ï¼©ãªã©ã§ä¾å¤ã®ç¨®é¡ã«ããå¦çãåãããã¨ãå¿ è¦ãªã¨ã©ã¼ï¼ä¾ãã°ãé信失æï¼ã¯Exceptionããç¶æ¿ããã®ãæã¾ããã¨æãã¾ãã |