N-Divisible Digits small program
You should try to find the O(1) algorithm for this problem, instead of using your current O(M) algorithm.

For example, given the input 9 500000001, your program takes 2.3 seconds (on my laptop) to run through the half-billion integers between 999999999 and 500000001. Whereas, using the relatively obvious O(1) algorithm, it takes 0.007 seconds.

Since this looks like homework and/or a Project Euler–type problem, I won't give the spoiler here.



Stylistically,


Prefer to write out std::cin, std::cout, etc., instead of wasting space at the top of the program with a bunch of using directives. It's shorter, cleaner, and (most importantly) more idiomatic to qualify names at the point of use instead of relying on using directives to pull them into scope.
Your function validNums uses exceptions for control flow, which is frowned upon in C++. Prefer to make it a function returning bool, and have its caller do something sensible (such as print an error message) if the given numbers aren't valid.
You have a named abstraction for largestNumber, when that could just as well have been a named local variable int largestNumber = pow(...);.
You don't have a named abstraction for produceTheActualAnswer; instead, you inline a complicated test if (answer = divisbleBy(largestNumber(num1), num2)) straight into main. This makes it unnecessarily difficult to switch out your bad old algorithm for a new and better one.
Putting an assignment inside an if condition is supremely bad style — so bad that both GCC and Clang (and probably MSVC too) will emit a warning on this code. You should write either

int answer = produceTheActualAnswer(num1, num2);
if (answer != 0) {
    ...
} else {
    ...
}


or, if you really want to use "interesting" features of C++, you might write

if (int answer = produceTheActualAnswer(num1, num2)) {
    ...
} else {
    ...
}


But I don't recommend the latter.




You should also consider taking your num1 and num2 parameters via the command line, instead of reading them from stdin:

int main(int argc, char **argv) {
    if (argc &lt; 3) {
        // maybe read them from stdin anyway
    } else {
        int m = std::atoi(argv[1]);
        int n = std::atoi(argv[2]);
        int answer = f(m, n);
        if (answer != 0) { ... } else { ... }
    }
}


This makes it easier to test your code quickly from the command line, and also makes it easy to time ./a.out 9 500000001 to see if you've beaten my 0.007 seconds yet. ;)