由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - js try catch finally question
相关主题
有人用 boost::property_tree 吗?c++:exception 一问
有没有简化的xml? (转载)大家对 exception 都是怎么处理的?
LISP is better than XML, but worse is better?出一道C++题
怎么写程序拿这个网页的数据?try catch question
从网页周期性抓取信息然后自动发邮件,应该怎么做?Exception 问题求助
有没有这样的blind JSON parserC++ try {} catch(...){} 能扑捉一切异常吗?
项目中又有人要用restful,结果我不restful了。。。弱问:c++里面throw就相当于return了吧?
.net 系列的。想向 back end 发展。该学哪些东西啊? (转载)真是痛恨喜欢 throw 的猪
相关话题的讨论汇总
话题: throw话题: catch话题: finally话题: found话题: try
进入Programming版参与讨论
1 (共1页)
s*****w
发帖数: 1527
1
my dummy code, try to find values from file, then return it.
try {
parse string from file
if find pattern, throw "found it"
} catch (e) {
if(e !== "found it") throw e
} finally {
res.json("pattern1":v1, "pattern2":v2});
}
问题是,假如文件中没找到,应该如何送一个空的json回去?
第二个throw处 (inside catch )应该如何处理?
many thanks !
f*******t
发帖数: 7549
2
...
} catch (e) {
if (e == "found it") {
res.json("");
return;
}
throw e;
}
别用finally
n*****t
发帖数: 22014
3
我去 。。。这么喜欢 throw 啊

【在 s*****w 的大作中提到】
: my dummy code, try to find values from file, then return it.
: try {
: parse string from file
: if find pattern, throw "found it"
: } catch (e) {
: if(e !== "found it") throw e
: } finally {
: res.json("pattern1":v1, "pattern2":v2});
: }
: 问题是,假如文件中没找到,应该如何送一个空的json回去?

l**********n
发帖数: 8443
4
同学,finally是无论如何都执行的。

【在 s*****w 的大作中提到】
: my dummy code, try to find values from file, then return it.
: try {
: parse string from file
: if find pattern, throw "found it"
: } catch (e) {
: if(e !== "found it") throw e
: } finally {
: res.json("pattern1":v1, "pattern2":v2});
: }
: 问题是,假如文件中没找到,应该如何送一个空的json回去?

s*****w
发帖数: 1527
5
我知道我写的是错的,问题是正确方法是什么

【在 l**********n 的大作中提到】
: 同学,finally是无论如何都执行的。
f*******t
发帖数: 7549
6
我不是给出答案了吗,还问什么?

【在 s*****w 的大作中提到】
: 我知道我写的是错的,问题是正确方法是什么
s*****w
发帖数: 1527
7
这个有些疑问,
1. finally不是很推崇的吗?
2. throw e 后面怎么处理?不会写
多谢!

【在 f*******t 的大作中提到】
: ...
: } catch (e) {
: if (e == "found it") {
: res.json("");
: return;
: }
: throw e;
: }
: 别用finally

b***i
发帖数: 3043
8
a={""};
try {
parse string from file
if find pattern, throw "found it"
} catch (e) {
if(e !== "found it") throw e
a={"pattern1":v1, "pattern2":v2};
} finally {
res.json(a);
}

【在 s*****w 的大作中提到】
: my dummy code, try to find values from file, then return it.
: try {
: parse string from file
: if find pattern, throw "found it"
: } catch (e) {
: if(e !== "found it") throw e
: } finally {
: res.json("pattern1":v1, "pattern2":v2});
: }
: 问题是,假如文件中没找到,应该如何送一个空的json回去?

l**********n
发帖数: 8443
9
new Promise(function(resolve, reject){
let pattern = doParse(file);
resolve(pattern);
}).then(function(pattern){
res.json("pattern1":v1, "pattern2":v2});
})
.catch(function(exp){
res.json(exp);
})

【在 s*****w 的大作中提到】
: my dummy code, try to find values from file, then return it.
: try {
: parse string from file
: if find pattern, throw "found it"
: } catch (e) {
: if(e !== "found it") throw e
: } finally {
: res.json("pattern1":v1, "pattern2":v2});
: }
: 问题是,假如文件中没找到,应该如何送一个空的json回去?

s*****w
发帖数: 1527
10
好像没改啥?

【在 b***i 的大作中提到】
: a={""};
: try {
: parse string from file
: if find pattern, throw "found it"
: } catch (e) {
: if(e !== "found it") throw e
: a={"pattern1":v1, "pattern2":v2};
: } finally {
: res.json(a);
: }

s*****w
发帖数: 1527
11
嚓,promise in node.js, 头晕死了

【在 l**********n 的大作中提到】
: new Promise(function(resolve, reject){
: let pattern = doParse(file);
: resolve(pattern);
: }).then(function(pattern){
: res.json("pattern1":v1, "pattern2":v2});
: })
: .catch(function(exp){
: res.json(exp);
: })

1 (共1页)
进入Programming版参与讨论
相关主题
真是痛恨喜欢 throw 的猪从网页周期性抓取信息然后自动发邮件,应该怎么做?
Java的例外处理问题什么情况下不用写throws有没有这样的blind JSON parser
node promise发出reject之后,是不是只能hit catch block ?项目中又有人要用restful,结果我不restful了。。。
C++ 的 exception handling.net 系列的。想向 back end 发展。该学哪些东西啊? (转载)
有人用 boost::property_tree 吗?c++:exception 一问
有没有简化的xml? (转载)大家对 exception 都是怎么处理的?
LISP is better than XML, but worse is better?出一道C++题
怎么写程序拿这个网页的数据?try catch question
相关话题的讨论汇总
话题: throw话题: catch话题: finally话题: found话题: try