Hi,
In c# i'm used to the following:
Code:
public class Foo{
public void Fun(CustomExceptionHandler customHandler){
try{
// ...
}
catch(DerivedExceptionType1 ex){ /* Custom handle the exception... */ }
catch(DerivedExceptionType2 ex){ /* Custom handle the exception... */ }
catch(DerivedExceptionType3 ex){ /* Custom handle the exception... */ }
}
public delegate void CustomExceptionHandler(Exception ex);
}
public void Fun(){
Foo foo = new Foo();
foo.Fun( ex => ClientExceptionHandler(ex) );
}
public void ClientExceptionHandler(Exception ex){
if(ex.GetType() == typeof(DerivedExceptionType1){
// ...
}
else if(ex.GetType() == typeof(DerivedExceptionType2){
// ...
}
else{ // ... }
Can anyone give an example of something similar in C++.
Using boost is fine, and it certainly doesn't have to be about handling exceptions.
Just something that shows how function pointers relate to lambdas?