Node 的异步特性是它最大的魅力,但是在带来便利的同时也带来了不少麻烦和坑,错误捕获就是一个。由于 Node 的异步特性,导致我们无法使用 try/catch 来捕获回调函数中的异常,例如:
try {
fs.read('SOME_FILE_DOES_NOT_EXIST', function readCallback(err, content) {
if (err) {
throw err; // 抛出异常
}| public class AESUtil | |
| { | |
| private static final Logger LOGGER = LoggerFactory.getLogger(AESUtil.class); | |
| /**将二进制转换成16进制 | |
| * @param buf | |
| * @return | |
| */ | |
| public static String parseByte2HexStr(byte buf[]) { | |
| StringBuffer sb = new StringBuffer(); |
| function Person(){ | |
| this.name = "person name"; | |
| } | |
| Person.prototype.showName = function(){ | |
| console.log(this.name); | |
| } | |
| function Student(){ | |
| this.name = "student name"; |
| //function is object | |
| //测试call方法,function.call(object, arguments...) ==> object.function(arguments...); 以object为上下文执行function方法 | |
| function add(a, b){ | |
| console.log(a + b); | |
| } | |
| function sub(a, b){ | |
| console.log(a - b); | |
| } |
| #!/usr/bin/perl | |
| use strict; | |
| chomp(my $filename=$ARGV[0]); | |
| chomp(my $username=$ARGV[1]); | |
| chomp(my $password=$ARGV[2]); | |
| if (!$filename || !$username || !$password) { | |
| print "USAGE: ./crypt.pl filename username password\n\n"; | |
| } else { |
| upstream some_app_server { | |
| server 127.0.0.1:9393; | |
| } | |
| server { | |
| listen 80; | |
| server_name my-upload-endpoint.com ; | |
| 1.install Ruby and Rubygems | |
| download ruby and install | |
| run Start Command Prompt With Ruby | |
| 2.update rubygems | |
| gem update --system | |
| 3.install vmc | |
| gem install vmc | |
| 4.targets the PaaS Cloud Foundry | |
| vmc target https://api.cloudfoundry.com | |
| 5.to show current target |
| introduction:http://en.wikipedia.org/wiki/Cron; | |
| #write out current crontab | |
| crontab -l > mycron | |
| #echo new cron into cron file | |
| echo "00 09 * * 1-5 echo hello" >> mycron | |
| #install new cron file | |
| crontab mycron | |
| rm mycron |
| mvn clean | |
| mvn eclipse:clean | |
| mvn eclipse:eclipse | |
| mvn package | |
| mvn dependency:copy-dependencies -DoutputDirectory=/target/lib | |
| mvn tomcat:run | |
| mvn jetty:run | |
| mvn clean tomcat:run -Dlog4j.debug=true |
| Run in bash: | |
| ./redis-cli KEYS preffix* | xargs ./redis-cli DEL |