dourui9570 2013-09-08 03:28
浏览 54
已采纳

Echo Uncaught Exception

I am making a bitcoin faucet using the coinbase api, and was looking to validate the address. I looked online to see if there are any good scripts, and couldnt find any so I decided to test and see if it was already built in the API, and it was! The the thing is that instead of just saying that is not a valid address it php displays a LONG error...

Fatal error: Uncaught exception 'Coinbase_ApiException' with message 'Please enter a valid email or bitcoin address' in C:\xampp\htdocs ahtnam\lib\Coinbase\Rpc.php:84 Stack trace: #0 C:\xampp\htdocs ahtnam\lib\Coinbase\Coinbase.php(39): Coinbase_Rpc->request('POST', 'transactions/se...', Array) #1 C:\xampp\htdocs ahtnam\lib\Coinbase\Coinbase.php(118): Coinbase->post('transactions/se...', Array) #2 C:\xampp\htdocs ahtnam\faucet.php(54): Coinbase->sendMoney('17FSKMPAyXGR7EQ...', '0.00000555', 'this is a test') #3 {main} thrown in C:\xampp\htdocs ahtnam\lib\Coinbase\Rpc.php on line 84

Is ther any way i can just set $address_error to "Please enter a valid Address" (not email) if this occurs and also not display the error? Thanks!

  • 写回答

2条回答 默认 最新

  • douxiandiyo58855 2013-09-08 04:04
    关注

    Expanding on aliasm2k's answer, you probably want to do it more like this:

    EDIT: Changed answer slightly based on comments discussion

    I think I was a bit unclear on what you were asking for in the comments.

     try {
         $result = $Coinbase->sendMoney($bitcoinaddress, '0.00000555', 'this is a test');
     catch(Exception $e) {
         echo $e->getMessage(); 
         exit;   //optional but you probably want to quit here and show the user
                 //the original form along with the error message to fix 
     }
    

    This is just going to echo "Please enter a valid email or bitcoin address." You wont get all of that other info because you are catching the exception and just displaying the message. Possible error messages are listed here.

    Also, if I can give you a slightly off-topic hint: If you want to find info about a particular address that has been used, try the blockchain block explorer api.

    And to simply check if an address is valid, you need to calculate that in your code or find a library function to do so. There's no master-list of addresses that an api would have. The last 4 bytes of the address are a double-sha-256 checksum of the preceding characters. That's sort-of an imprecise description I'm giving you, by the way, but check here for a working php example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度