Skip to content

Commit 29fef0b

Browse files
committed
Merge pull request #5360
71acb86 print the caught error instead of raising an error (Heath)
2 parents 93a8c46 + 71acb86 commit 29fef0b

File tree

1 file changed

+71
-73
lines changed

1 file changed

+71
-73
lines changed

contrib/bitrpc/bitrpc.py

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
try:
2121
path = raw_input("Enter destination path/filename: ")
2222
print access.backupwallet(path)
23-
except:
24-
print "\n---An error occurred---\n"
25-
23+
except Exception as inst:
24+
print inst
25+
2626
elif cmd == "encryptwallet":
2727
try:
2828
pwd = getpass.getpass(prompt="Enter passphrase: ")
@@ -32,29 +32,29 @@
3232
print "\n---Wallet encrypted. Server stopping, restart to run with encrypted wallet---\n"
3333
else:
3434
print "\n---Passphrases do not match---\n"
35-
except:
36-
print "\n---An error occurred---\n"
35+
except Exception as inst:
36+
print inst
3737

3838
elif cmd == "getaccount":
3939
try:
4040
addr = raw_input("Enter a Bitcoin address: ")
4141
print access.getaccount(addr)
42-
except:
43-
print "\n---An error occurred---\n"
42+
except Exception as inst:
43+
print inst
4444

4545
elif cmd == "getaccountaddress":
4646
try:
4747
acct = raw_input("Enter an account name: ")
4848
print access.getaccountaddress(acct)
49-
except:
50-
print "\n---An error occurred---\n"
49+
except Exception as inst:
50+
print inst
5151

5252
elif cmd == "getaddressesbyaccount":
5353
try:
5454
acct = raw_input("Enter an account name: ")
5555
print access.getaddressesbyaccount(acct)
56-
except:
57-
print "\n---An error occurred---\n"
56+
except Exception as inst:
57+
print inst
5858

5959
elif cmd == "getbalance":
6060
try:
@@ -64,57 +64,57 @@
6464
print access.getbalance(acct, mc)
6565
except:
6666
print access.getbalance()
67-
except:
68-
print "\n---An error occurred---\n"
67+
except Exception as inst:
68+
print inst
6969

7070
elif cmd == "getblockbycount":
7171
try:
7272
height = raw_input("Height: ")
7373
print access.getblockbycount(height)
74-
except:
75-
print "\n---An error occurred---\n"
74+
except Exception as inst:
75+
print inst
7676

7777
elif cmd == "getblockcount":
7878
try:
7979
print access.getblockcount()
80-
except:
81-
print "\n---An error occurred---\n"
80+
except Exception as inst:
81+
print inst
8282

8383
elif cmd == "getblocknumber":
8484
try:
8585
print access.getblocknumber()
86-
except:
87-
print "\n---An error occurred---\n"
86+
except Exception as inst:
87+
print inst
8888

8989
elif cmd == "getconnectioncount":
9090
try:
9191
print access.getconnectioncount()
92-
except:
93-
print "\n---An error occurred---\n"
92+
except Exception as inst:
93+
print inst
9494

9595
elif cmd == "getdifficulty":
9696
try:
9797
print access.getdifficulty()
98-
except:
99-
print "\n---An error occurred---\n"
98+
except Exception as inst:
99+
print inst
100100

101101
elif cmd == "getgenerate":
102102
try:
103103
print access.getgenerate()
104-
except:
105-
print "\n---An error occurred---\n"
104+
except Exception as inst:
105+
print inst
106106

107107
elif cmd == "gethashespersec":
108108
try:
109109
print access.gethashespersec()
110-
except:
111-
print "\n---An error occurred---\n"
110+
except Exception as inst:
111+
print inst
112112

113113
elif cmd == "getinfo":
114114
try:
115115
print access.getinfo()
116-
except:
117-
print "\n---An error occurred---\n"
116+
except Exception as inst:
117+
print inst
118118

119119
elif cmd == "getnewaddress":
120120
try:
@@ -123,8 +123,8 @@
123123
print access.getnewaddress(acct)
124124
except:
125125
print access.getnewaddress()
126-
except:
127-
print "\n---An error occurred---\n"
126+
except Exception as inst:
127+
print inst
128128

129129
elif cmd == "getreceivedbyaccount":
130130
try:
@@ -134,8 +134,8 @@
134134
print access.getreceivedbyaccount(acct, mc)
135135
except:
136136
print access.getreceivedbyaccount()
137-
except:
138-
print "\n---An error occurred---\n"
137+
except Exception as inst:
138+
print inst
139139

140140
elif cmd == "getreceivedbyaddress":
141141
try:
@@ -145,15 +145,15 @@
145145
print access.getreceivedbyaddress(addr, mc)
146146
except:
147147
print access.getreceivedbyaddress()
148-
except:
149-
print "\n---An error occurred---\n"
148+
except Exception as inst:
149+
print inst
150150

151151
elif cmd == "gettransaction":
152152
try:
153153
txid = raw_input("Enter a transaction ID: ")
154154
print access.gettransaction(txid)
155-
except:
156-
print "\n---An error occurred---\n"
155+
except Exception as inst:
156+
print inst
157157

158158
elif cmd == "getwork":
159159
try:
@@ -162,8 +162,8 @@
162162
print access.gettransaction(data)
163163
except:
164164
print access.gettransaction()
165-
except:
166-
print "\n---An error occurred---\n"
165+
except Exception as inst:
166+
print inst
167167

168168
elif cmd == "help":
169169
try:
@@ -172,8 +172,8 @@
172172
print access.help(cmd)
173173
except:
174174
print access.help()
175-
except:
176-
print "\n---An error occurred---\n"
175+
except Exception as inst:
176+
print inst
177177

178178
elif cmd == "listaccounts":
179179
try:
@@ -182,8 +182,8 @@
182182
print access.listaccounts(mc)
183183
except:
184184
print access.listaccounts()
185-
except:
186-
print "\n---An error occurred---\n"
185+
except Exception as inst:
186+
print inst
187187

188188
elif cmd == "listreceivedbyaccount":
189189
try:
@@ -193,8 +193,8 @@
193193
print access.listreceivedbyaccount(mc, incemp)
194194
except:
195195
print access.listreceivedbyaccount()
196-
except:
197-
print "\n---An error occurred---\n"
196+
except Exception as inst:
197+
print inst
198198

199199
elif cmd == "listreceivedbyaddress":
200200
try:
@@ -204,8 +204,8 @@
204204
print access.listreceivedbyaddress(mc, incemp)
205205
except:
206206
print access.listreceivedbyaddress()
207-
except:
208-
print "\n---An error occurred---\n"
207+
except Exception as inst:
208+
print inst
209209

210210
elif cmd == "listtransactions":
211211
try:
@@ -216,8 +216,8 @@
216216
print access.listtransactions(acct, count, frm)
217217
except:
218218
print access.listtransactions()
219-
except:
220-
print "\n---An error occurred---\n"
219+
except Exception as inst:
220+
print inst
221221

222222
elif cmd == "move":
223223
try:
@@ -230,8 +230,8 @@
230230
print access.move(frm, to, amt, mc, comment)
231231
except:
232232
print access.move(frm, to, amt)
233-
except:
234-
print "\n---An error occurred---\n"
233+
except Exception as inst:
234+
print inst
235235

236236
elif cmd == "sendfrom":
237237
try:
@@ -245,8 +245,8 @@
245245
print access.sendfrom(frm, to, amt, mc, comment, commentto)
246246
except:
247247
print access.sendfrom(frm, to, amt)
248-
except:
249-
print "\n---An error occurred---\n"
248+
except Exception as inst:
249+
print inst
250250

251251
elif cmd == "sendmany":
252252
try:
@@ -258,8 +258,8 @@
258258
print access.sendmany(frm,to,mc,comment)
259259
except:
260260
print access.sendmany(frm,to)
261-
except:
262-
print "\n---An error occurred---\n"
261+
except Exception as inst:
262+
print inst
263263

264264
elif cmd == "sendtoaddress":
265265
try:
@@ -271,16 +271,16 @@
271271
print access.sendtoaddress(to,amt,comment,commentto)
272272
except:
273273
print access.sendtoaddress(to,amt)
274-
except:
275-
print "\n---An error occurred---\n"
274+
except Exception as inst:
275+
print inst
276276

277277
elif cmd == "setaccount":
278278
try:
279279
addr = raw_input("Address: ")
280280
acct = raw_input("Account:")
281281
print access.setaccount(addr,acct)
282-
except:
283-
print "\n---An error occurred---\n"
282+
except Exception as inst:
283+
print inst
284284

285285
elif cmd == "setgenerate":
286286
try:
@@ -290,36 +290,36 @@
290290
print access.setgenerate(gen, cpus)
291291
except:
292292
print access.setgenerate(gen)
293-
except:
294-
print "\n---An error occurred---\n"
293+
except Exception as inst:
294+
print inst
295295

296296
elif cmd == "settxfee":
297297
try:
298298
amt = raw_input("Amount:")
299299
print access.settxfee(amt)
300-
except:
301-
print "\n---An error occurred---\n"
300+
except Exception as inst:
301+
print inst
302302

303303
elif cmd == "stop":
304304
try:
305305
print access.stop()
306-
except:
307-
print "\n---An error occurred---\n"
306+
except Exception as inst:
307+
print inst
308308

309309
elif cmd == "validateaddress":
310310
try:
311311
addr = raw_input("Address: ")
312312
print access.validateaddress(addr)
313-
except:
314-
print "\n---An error occurred---\n"
313+
except Exception as inst:
314+
print inst
315315

316316
elif cmd == "walletpassphrase":
317317
try:
318318
pwd = getpass.getpass(prompt="Enter wallet passphrase: ")
319319
access.walletpassphrase(pwd, 60)
320320
print "\n---Wallet unlocked---\n"
321-
except:
322-
print "\n---An error occurred---\n"
321+
except Exception as inst:
322+
print inst
323323

324324
elif cmd == "walletpassphrasechange":
325325
try:
@@ -328,10 +328,8 @@
328328
access.walletpassphrasechange(pwd, pwd2)
329329
print
330330
print "\n---Passphrase changed---\n"
331-
except:
332-
print
333-
print "\n---An error occurred---\n"
334-
print
331+
except Exception as inst:
332+
print inst
335333

336334
else:
337335
print "Command not found or not supported"

0 commit comments

Comments
 (0)