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 ÖУ¬²¢²»±íʾ
Ïà¹ØÎĵµ£º
´Ó5ÔÂ5ºÅ½øÈë¾ÍÒµ°àµ½ÏÖÔÚËÄÌìµÄʱ¼äÁË£¬ÉÏÁËÕ⼸Ìì¿Î·¢ÏÖ¾ÍÒµ°àµÄÇ¿¶ÈÕæµÄºÜ´ó£¬²»ÏñÒÔÇ°»ù´¡°àµÄʱºòÄÇô»¹±È½ÏÇáËÉ£¬ÒѾ½¥½¥¸Ð¾õµ½Á˳ÔÁ¦£¬ÒòΪÏÖÔÚÉÏ¿ÎÐèÒª½²½âµÄ֪ʶµãÌ«¶à£¬ÓÐʱºòÏÂÎçÀÏʦ½²µ½6µã¶àÖÓ²ÅÏ¿Σ¬¿ÎÉϵÄÁ·Ï°Ê±¼äÔ½À´Ô½ÉÙÁË£¬Ö»ÄÜ×Ô¼ºÀûÓÿκóµÄʱ¼ä¶àÁ·Ï°Êµ¼ù£¬Ðí¶à¶«Î÷»¹¶¼ÊǵÚÒ»´Î ......
ÎÊÌâµÄÒýÈëÊÇÒòΪÏÂÎçÔÚȺÀï¿´µ½ÁËÒ»¸öÍøÓѵÄÎÊÌ⣺
¸ø¶¨ÈçÏÂJava ´úÂ룬±àÒëÔËÐкó£¬Êä³ö½á¹ûÊÇ£¨ £©¡£
public class Test {
public static void main(String [ ] args) {
StringBuffer a = new StringBuffer(“A”);
&n ......
import javax.swing.JOptionPane;
public class San {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
&n ......
ÈκÎÊÂÎïµÄ²úÉú¼ÈÓбØÈ»µÄÔÒòÒ²ÓÐżȻµÄÒòËØ£¬javaÓïÑԵijöÏÖÒ²ÑéÖ¤ÁËÕâÒ»µã¡£1991Ä꣬ÃÀ¹úSun Microsystems¹«Ë¾µÄij¸öÑо¿Ð¡×éΪÁËÄܹ»ÔÚÏû·Ñµç×Ó²úÆ·ÉÏ¿ª·¢Ó¦ÓóÌÐò£¬»ý¼«Ñ°ÕÒºÏÊʵıà³ÌÓïÑÔ¡£Ïû·Ñµç×Ó²úÆ·ÖÖÀà·±¶à£¬°üÀ¨PDA¡¢»ú¶¥ºÐ¡¢ÊÖ»úµÈµÈ£¬¼´Ê¹ÊÇͬһÀàÏû·Ñµç×Ó²úÆ·Ëù²ÉÓõĴ¦ÀíоƬºÍ²Ù×÷ϵͳҲ²»Ïàͬ£¬Ò²´æÔÚ×Å¿ ......
ÒÆλÔËËã·û
°üÀ¨£º
“>> ÓÒÒÆ”£»“<< ×óÒÆ”£»“>>> ÎÞ·ûºÅÓÒÒÆ”
Àý×Ó£º
-5>>3=-1
1111 1111 1111 1111 1111 1111 1111 1011
1111 1111 1111 1111 1111 1111 1111 1111
Æä½á¹ûÓë Math.floor((double)- ......