JavaÁ½ÖÖÒ쳣ģʽ
JavaÀïÓиöºÜÖØÒªµÄÌØÉ«ÊÇException £¬Ò²¾ÍÊÇ˵ÔÊÐí³ÌÐò²úÉúÀýÍâ×´¿ö¡£¶øÔÚѧJava µÄʱºò£¬ÎÒÃÇÒ²Ö»ÖªµÀException µÄд·¨£¬È´Î´±ØÕæÄÜÁ˽ⲻͬÖÖÀàµÄException µÄÇø±ð¡£
Ê×ÏÈ£¬ÄúÓ¦¸ÃÖªµÀµÄÊÇJava ÌṩÁËÁ½ÖÖException µÄģʽ£¬Ò»ÖÖÊÇÖ´ÐеÄʱºòËù²úÉúµÄException (Runtime Exception)£¬ÁíÍâÒ»ÖÖÔòÊÇÊÜ¿ØÖƵÄException (Checked Exception)¡£
ËùÓеÄChecked Exception ¾ù´Ójava.lang.Exception ¼Ì³Ð¶øÀ´£¬¶øRuntime Exception Ôò¼Ì³Ðjava.lang.RuntimeException »òjava.lang.Error (ʵ¼ÊÉÏjava.lang.RuntimeException µÄÉÏÒ»²ãÒ²ÊÇjava.lang.Exception)¡£
µ±ÎÒÃÇ׫д³ÌÐòµÄʱºò£¬ÎÒÃǺܿÉÄÜ»á¶ÔÑ¡ÔñijÖÖÐÎʽµÄException ¸Ðµ½À§ÈÅ£¬µ½µ×ÎÒÓ¦¸ÃÑ¡ÔñRuntime Exception »¹ÊÇChecked Exception £¿
Æäʵ£¬ÔÚÔË×÷ÉÏ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýClass µÄMethod ÈçºÎ²úÉúij¸öExceptionÒÔ¼°Ä³¸ö³ÌÐòÈçºÎ´¦ÀíÕâ¸ö±»²úÉúÀ´µÄException À´Á˽âËüÃÇÖ®¼äµÄ²îÒì¡£
Ê×ÏÈÎÒÃÇÏȽ¨Á¢Ò»¸öException
public class CException extends Exception
{
public CException() {}
public CException(String message)
{
super(message);
}
}
È»ºóÎÒÃÇ׫дһ¸ö¿ÉÄܲúÉú CException µÄ Class
public class testException
{
public void method1() throws CException
{
throw new CException("Test Exception");
}
public void method2(String msg)
{
if(msg == null)
{
throw new NullPointerException("Message is null");
}
}
public void method3() throws CException
{
method1();
}
// ÒÔÏÂÊ¡ÂÔ
// ...
}
ÔÚÕâÈý¸ömethod ÖУ¬ÎÒÃÇ¿´µ½ÁËmethod1 ºÍmethod2 µÄ³ÌÐòÂëÄÚ¶¼»á²úÉúException£¬µ«method3 µÄ³ÌÐòÂëÖÐ(´óÀ¨ºÅÄÚ)£¬²¢Ã»²úÉúException£¬µ«ÔÚmethod3 µÄ¶¨ÒåÖУ¬°µÊ¾ÁËÕâ¸ömethod ¿ÉÄܲúÉúCException¡£ ºô½Ðmethod1() µÄ³ÌÐò£¬±ØÐ뽫method1() °üº¬ÔÚtry Óëcatch ÖУ¬È磺
public class runtest
{
// ....
public static void main(String argv[])
{
testException te = new testException();
try
{
te.method1();
}
catch(CException ce)
{
// ....
}
}
// ...
}
ËäÈ»°üº¬ÔÚtry Óëcatch ÖУ¬²¢²»±íʾ
Ïà¹ØÎĵµ£º
ÈκÎÊÂÎïµÄ²úÉú¼ÈÓбØÈ»µÄÔÒòÒ²ÓÐżȻµÄÒòËØ£¬javaÓïÑԵijöÏÖÒ²ÑéÖ¤ÁËÕâÒ»µã¡£1991Ä꣬ÃÀ¹úSun Microsystems¹«Ë¾µÄij¸öÑо¿Ð¡×éΪÁËÄܹ»ÔÚÏû·Ñµç×Ó²úÆ·ÉÏ¿ª·¢Ó¦ÓóÌÐò£¬»ý¼«Ñ°ÕÒºÏÊʵıà³ÌÓïÑÔ¡£Ïû·Ñµç×Ó²úÆ·ÖÖÀà·±¶à£¬°üÀ¨PDA¡¢»ú¶¥ºÐ¡¢ÊÖ»úµÈµÈ£¬¼´Ê¹ÊÇͬһÀàÏû·Ñµç×Ó²úÆ·Ëù²ÉÓõĴ¦ÀíоƬºÍ²Ù×÷ϵͳҲ²»Ïàͬ£¬Ò²´æÔÚ×Å¿ ......
4£® ¸ßÐÔÄÜ
¡¡¡¡ËäÈ»javaÊǽâÊÍÖ´Ðеģ¬µ«ËüÈÔÈ»¾ßÓзdz£¸ßµÄÐÔÄÜ£¬ÔÚһЩÌض¨µÄCPUÉÏ£¬java×Ö½ÚÂë¿ÉÒÔ¿ìËÙµÄת»»³ÉΪ»úÆ÷Âë½øÐÐÖ´ÐС£¶øÇÒjava×Ö½ÚÂë¸ñʽµÄÉè¼Æ¾ÍÊÇÕë¶Ô»úÆ÷ÂëµÄת»»£¬Êµ¼Êת»»Ê±Ï൱¼ò±ã£¬×Ô¶¯µÄ¼Ä´æÆ÷·ÖÅäÓë±àÒëÆ÷¶Ô×Ö½ÚÂëµÄһЩÓÅ»¯¿Éʹ֮Éú³É¸ßÖÊÁ¿µÄ´úÂë¡£Ëæ×ÅjavaÐéÄâ»úµÄ¸Ä½øºÍ"¼´Ê±±àÒë"£¨just in ......
½üÆÚµÄÒ»¸öÏîÄ¿ÐèҪʵÏÖÉãÏñͷͼÏñ²É¼¯£¬¾¹ýһϵÁеÄÕÛÌÚÒÔºó£¬ÖÕÓÚʵÏÖÁËÕâ¸ö¹¦ÄÜ£¬ÏÖÕûÀíһϡ£
±¾Éí¾Íjava¼¼ÊõÀ´Ëµ£¬ÒªÊµÏÖÉãÏñÍ·¶þ´Î¿ª·¢£¬²É¼¯ÉãÏñͷͼƬ£¬ÐèҪʹÓõ½JMF£¬JMFÊʺÏʹÓÃÔÚj2se³ÌÐòµ±ÖУ¬ÎÒÐèÒªÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬ºÜÃ÷ÏÔJMFÊǸ㲻¶¨ÁË£¬Ïë¹ýдһ¸öapplet³ÌÐò£¬Ö»ÊÇÄǶ«Î÷ÒªÇó¿Í»§¶Ë±ØÐëÒªÓÐjre»·¾ ......
Java»ù´¡·½Ãæ:
1¡¢×÷ÓÃÓòpublic,private,protected,ÒÔ¼°²»Ð´Ê±µÄÇø±ð
´ð£ºÇø±ðÈçÏ£º
×÷ÓÃÓò µ±Ç°Àà ͬһpackage ×ÓËïÀà ÆäËûpackage
public& ......
³öÏÖÕâ¸ö´íÎó£¬ËÑË÷µ½1¡¢ÐÞ¸Äeclipse.ini£»2¡¢Ìí¼Ó»·¾³±äÁ¿JAVA_OPTS=-Xms64m -Xmx512m£¬3¡¢ÔÚrun configurations->program argumentsÔö¼ÓXms64m -Xmx512m£¬¾ùÎÞЧ¡£
×îºó½â¾ö°ì·¨£¬ÔÚÓëprogram argumentsһǽ֮¸ôµÄVM argumentsÖÐÌí¼ÓXms64m -Xmx512m¸ã¶¨¡£ ......