정의되지 않은 Object 의 호출시 예외처리 샘플

 

jQuery("button").bind(
	"click",function()
	{
    	console.log( "this.id => " + this.id );
        
    	let goUrl	=   "[TARGE_TURL]";
        let searchValue   =   jQuery("#searchValue").val();
        try {
        	switch(this.id)
        	{
	            case "btn_sarch_submit":
                    if( searchValue.length > 0 )
                    {
                    goUrl	=	goUrl + "?searchValue=" + encodeURIComponent( searchValue );
                    window.location.href	=	goUrl;
                    }// end if
                break;
                case "btn_search_reset":
	                window.location.href	=	goUrl;
                break;
                case "btn_addnew":
    	            window.location.href	=	goUrl;
                break;
            }//	end switch
        }catch (err){
        	alert(err)
        	return false;
        }
	}
);