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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路