最近开始用Ruby进行编程,并且正在寻找异常处理。
想知道是否在C#中ensure的Ruby等价物finally?比如:
file = File.open(""myFile.txt"", ""w"")
begin
file << ""#{content} \n""
rescue
#handle the error here
ensure
file.close unless file.nil?
end
或者应该这样做?
#store the file
file = File.open(""myFile.txt"", ""w"")
begin
file << ""#{content} \n""
file.close
rescue
#handle the error here
ensure
file.close unless file.nil?
end
可以尝试下:
<script type="text/javascript">
window.sitescriptdata = {};
window.sitescriptdata.foo = ( <?php echo json_encode( $structure ); ?> );
</script>
对于基本内容,可以节省执行Ajax回调的操作:
<div id="foobar">
<div><object class="metaobject">
<param name="data" value="<?php echo htmlentities(json_encode($data), ENT_QUOTES );?>" />
</object></div>
</div>
倾向于使用这个JSON对象:
json_encode($data);