C++ c++;捕获未捕获异常(异常类型)

C++ c++;捕获未捕获异常(异常类型),c++,exception,C++,Exception,以下是一段代码,我有例外: try { hashTable->lookup(bufDescTable[clockHand].file, bufDescTable[clockHand].pageNo, dummyFrame); } catch (HashNotFoundException *e) { } catch (HashNotFoundException &e) { } catch (HashNotFoundE

以下是一段代码,我有例外:

try {
        hashTable->lookup(bufDescTable[clockHand].file, bufDescTable[clockHand].pageNo, dummyFrame);
    }
    catch (HashNotFoundException *e) {

    }
    catch (HashNotFoundException &e) {

    }
    catch (HashNotFoundException e) {

    }
    catch (...) {

    }
在hashTable->lookup中生成异常,如下所示:

throw HashNotFoundException(file->filename(), pageNo);
下面是哈希表查找方法签名

 void BufHashTbl::lookup(const File* file, const PageId pageNo, FrameId &frameNo)  
异常会升级到最高级别,好像这不关任何人的事

我正在使用Mac(Lion)和Xcode(编译器使用g++)

如有任何想法,将不胜感激


谢谢

我们确实需要一个完整的示例/进一步的信息来为您诊断

例如,以下版本的代码为我编译并运行,输出
HashNotFoundException&

请注意,代码与原始代码相比有一些细微的更改,但这些更改不应是实质性的

但是,它确实会生成以下警告:

example.cpp: In function ‘int main()’:
example.cpp:42: warning: exception of type ‘HashNotFoundException’ will be caught
example.cpp:38: warning:    by earlier handler for ‘HashNotFoundException’
我在OS X 10.8.5上使用
i686-apple-darwin11-llvm-g++-4.2(GCC)4.2.1(基于apple Inc.build 5658)(llvm build 2336.11.00)

#include <iostream>
#include <sstream>

struct BadgerDbException {};
struct PageId {};
struct FrameId {};

struct HashNotFoundException : public BadgerDbException {
  std::string name;
  PageId pageNo;
  HashNotFoundException(const std::string& nameIn, PageId pageNoIn)
    : BadgerDbException(), name(nameIn), pageNo(pageNoIn) {
    }
};

struct HashTable {
  void lookup(void* file, const PageId pageNo, FrameId &frameNo) {
    throw HashNotFoundException("a file", pageNo);
  }
};    

int main() {
  HashTable * hashTable = new HashTable;
  PageId a_Page_ID;
  FrameId dummyFrame;
  try {
    FrameId dummyFrame;
    hashTable->lookup(NULL, a_Page_ID, dummyFrame);
  }
  catch (HashNotFoundException *e) { std::cout<<"HashNotFoundException *"<<std::endl;}
  catch (HashNotFoundException &e) { std::cout<<"HashNotFoundException &"<<std::endl;}
  catch (HashNotFoundException e)  { std::cout<<"HashNotFoundException"<<std::endl; }
  catch (...)                      { std::cout<<"... exception"<<std::endl; }
}
#包括
#包括
结构BadgerDbException{};
结构PageId{};
结构框架ID{};
结构HashNotFoundException:公共BadgerDbException{
std::字符串名;
PageId-pageNo;
HashNotFoundException(const std::string&nameIn,PageId pageNoIn)
:BadgerDbException(),name(nameIn),pageNo(pageNoIn){
}
};
结构哈希表{
void查找(void*文件、const PageId pageNo、FrameId和frameNo){
抛出HashNotFoundException(“一个文件”,pageNo);
}
};    
int main(){
哈希表*哈希表=新哈希表;
PageId a_Page_ID;
FrameId-dummyFrame;
试一试{
FrameId-dummyFrame;
哈希表->查找(空,一个页面ID,dummyFrame);
}

catch(HashNotFoundException*e){std::coutCan您可以共享“lookup”的函数签名吗函数。具体检查它可以抛出的异常类型是否有限制。将其添加到问题中。在.cpp中没有限制。您可以生成SSCE吗?可能还值得一提的是您正在使用的编译器和操作系统。减少了问题。BadgerDBException:)我使用的是Apple LLVM编译器4.2。本质上这是这正是我的代码所做的。唯一的区别是HashNotFoundException构造函数声明为显式的-但从我所读到的来看,这不应该有什么区别。。。